Question meaning:
Given the numbers of letters and their corresponding numbers, calculate the number of different characters
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1261
Question Analysis:
Directly apply the combination formula, s! /(Ai !) S: Total number of characters AI: the number of characters I, using arrays to achieve high-precision combination Formula
Do not directly request s! It will time out. We need to calculate both the upper and lower, and describe the maximum number of common approx. We can simulate the multiplication of the remaining values.
AC code:
/**
* S! /(Ai !) S: Total characters AI: the number of I characters
* (High Precision)
*/
# Include <iostream>
# Include <cstring>
# Include <algorithm>
Using namespace STD;
Int CMP (int A, int B ){
Return A> B;
}
Int gcd (int A, int B ){
If (B = 0) return;
Else return gcd (B, A % B );
}
Int main ()
{
Int n, a [30], sum [501]; // Sun Storage result
Int S2 [400], B [27] [15]; // storage I for ease of Computing
While (CIN> N & N ){
Int I, J, K;
Int S = 0;
For (I = 1; I <= N; I ++ ){
Cin> A [I];
S + = A [I];
}
For (I = 1; I <= s; I ++) {// record all numbers
S2 [I] = I;
}
For (k = 1; k <= N; k ++ ){
For (j = 2; j <= A [k]; j ++ ){
Int M = J;
While (M> 1 ){
For (I = 1; I <= s; I ++ ){
Int M1 = gcd (s2 [I], M );
M = m/M1;
S2 [I] = S2 [I]/M1;
}
}
}
}
Memset (sum, 0, sizeof (SUM ));
// Cout <m <Endl;
Sum [0] = 1;
For (I = 1; I <= s; I ++) {// No approximate value for simulated Multiplication
// Cout <S2 [I] <"";
Int flag = 0;
If (s2 [I]! = 1) For (j = 0; j <= 500; j ++ ){
Int Ss = sum [J] * S2 [I] + flag;
Sum [J] = SS % 10;
Flag = SS/10;
}
// S1 * = S2 [I];
}
For (I = 500 ;! Sum [I]; I --);
// Cout <I <Endl;
For (j = I; j> = 0; j --){
Cout <sum [J];
}
Cout <Endl;
}
Return 0;
}
Hdu1261 (Application of High Precision + combination formula)