Translation of the meaning of problems
Give you a digital sequence A (length of no more than 18), asked how many sequences B satisfy ①A all figures are sure to appeared in B; ② B all the numbers must also be appeared in A; ③ sequence B can not begin with 0
Input # 1
97
Output # 1
2
Problem-solving ideas
To count the number of each of a sequence number that appears in the input string can then turn into type int, may be directly scanf ( "% 1d", & a);
Then each digit appears dfs case
Direct sleeve formula ans + = factorial of the number of all the numbers / factorial of the number of digits in each of the first product of a case -0
AC Code
#include<bits/stdc++.h> using namespace std; typedef long long ll; int num[10],temp[10]; ll jc[20],ans=0; void dfs(int x) { if(x==10) { int cnt=0; for(int i=0; i<10; ++i) cnt += temp[i]; ll p=jc[cnt]; for(int i=0; i<10; ++i) p/=jc[temp[i]]; if(temp[0]>=1) p-=(p*temp[0]/cnt); ans+=p; return; } for(int i=1; i<=num[x]; ++i) { temp[x]=i; dfs(x+1); } if(num[x]==0) dfs(x+1); } int main() { int a; while(scanf("%1d",&a)!=EOF){ num[a]++; } jc[0]=1; for(int i=1; i<=19; i++) jc[i]=jc[i-1]*i; dfs(0); cout<<ans<<endl; return 0; }