Test instructions: Give you the number of n, and how much to add to their full arrangement
Idea: For this problem, assuming that the number K1 in the first place, and then find the remaining N-1-bit permutation number NUM1, we can know K1 in the first position when the arrangement of how many kinds of kind1,
Similarly, assuming that the number K2 in the first position and then find the remaining N-1-bit permutation number num2, we can know K2 in the first position when the arrangement of how many kinds of kind2,
K1*num1+k1*num2.....+kn*numn is the number we ask for all the contributions to the first place, we know the contribution of the first bit = contribution to the second position = the contribution of the third person .....
Add all the contributions and you can find the results.
Knowledge:
1, how to find the full array of repetition number
Element representation: A1,A1,... A1, a2,a2,... A2,......., An,an,... an
Among them, the number of A1 is N1, the number of A2 is N2, and so on, the total number is m.
You can prove the number of non-repeating permutations: m!/(n1!*n2!*...*nn!)
Code:
#include <iostream>#include<cstdio>#include<cstring>#defineull unsigned long Longusing namespacestd;ull c[ the][ the];voidGet_c () {memset (C,0,sizeof(C)); c[1][0]=1; c[1][1]=1; for(intI=2; i<= A; i++) { for(intj=0; j<=i;j++) {C[i][j]=c[i-1][j]+c[i-1][j-1]; } }}intMain () {intN; intdata[ the]; intnum[Ten]; Get_c (); while(cin>>n&&N) {memset (num,0,sizeof(num)); for(intI=0; i<n;i++) {cin>>Data[i]; Num[data[i]]++; } ull ans=0; for(intI=0; i<=9; i++) {ull k=0; if(Num[i]) {k=1; intm=n-1; Num[i]--; for(intj=0; j<=9; j + +) { if(num[j]==0)Continue; K=k*C[m][num[j]]; M=m-Num[j]; //cout<<k<<endl;} Num[i]++; } ans=ans+i*K; } ull sum=0; for(intI=0; i<n;i++) Sum=sum*Ten+ans; cout<<sum<<Endl; } return 0;}
Uva 11076 Add Again (number theory + combinatorial mathematics)