Numbers
Bobo has
distinct integers
in
. He writes them in decimal notation without leading zeros in a row, obtaning a string
.
Given the string , find the number of possible array of integers .
Input
The input consists of several test cases and is terminated by end-of-file.
Each test case contains a string .
There are at most
test cases.
Output
For each test case, print an integer which denotes the result.
思路:
搜一下就好了
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <list>
using namespace std;
char s[105];
int vis[105],len;
int dfs(int i)
{
if(i == len + 1)
{
return 1;
}
int ans = 0;
int x = s[i] - '0';
if(!vis[x])
{
vis[x] = 1;
ans += dfs(i + 1);
vis[x] = 0;
}
if(i != len && x != 0)
{
int y = s[i + 1] - '0';
int num = x * 10 + y;
if(!vis[num])
{
vis[num] = 1;
ans += dfs(i + 2);
vis[num] = 0;
}
}
return ans;
}
int main()
{
while(~scanf("%s",s + 1))
{
memset(vis,0,sizeof(vis));
len = (int)strlen(s + 1);
printf("%d\n",dfs(1));
}
return 0;
}