Combinatorics --cf991E

/ * 
If there is a one, then this one must be present 
to enumerate all cases, the calculation of each case EXTRAS another operator 
* / 
#include <bits / STDC ++ H.>
 A using  namespace std;
 #define LL Long Long 
LL ANS , n-, CNT [ . 11 ], F. [ 20 is ], A [ . 11 ]; 

LL Calc () { 
    LL RES = . 1 , len = 0 ;
     for ( int I = . 1 ; I <= . 9 ; I ++) len + = A [ I]; 
    RES = F. [len];
     for ( int I = . 1 ; I <= . 9 ; I ++  )
        RES/=F[a[i]];
    for(int i=1;i<=a[0];i++)
        res*=(len+i-1);
    res/=F[a[0]];
    return res;
}

int main(){
    F[0]=1;
    for(ll i=1;i<=18;i++)F[i]=i*F[i-1];
     
    cin>>n;
    while(n){
        cnt[n%10]++;
        n/=10;
    }
            
    for(a[0]=(cnt[0]!=0);a[0]<=cnt[0];a[0]++)
    for(a[1]=(cnt[1]!=0);a[1]<=cnt[1];a[1]++)
    for(a[2]=(cnt[2]!=0);a[2]<=cnt[2];a[2]++)
    for(a[3]=(cnt[3]!=0);a[3]<=cnt[3];a[3]++)
    for(a[4]=(cnt[4]!=0);a[4]<=cnt[4];a[4]++)
    for(a[5]=(cnt[5]!=0);a[5]<=cnt[5];a[5]++)
    for(a[6]=(cnt[6]!=0);a[6]<=cnt[6];a[6]++)
    for(a[7]=(cnt[7]!=0);a[7]<=cnt[7];a[7]++)
    for(a[8]=(cnt[8]!=0);a[8]<=cnt[8];a[8]++)
    for(a[9]=(cnt[9]!=0);a[9]<=cnt[9];a[9]++)
        ans+=calc();
    cout<<ans<<'\n';    
}

 

Guess you like

Origin www.cnblogs.com/zsben991126/p/11110123.html