Hdu1261 (Application of High Precision + combination formula)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.