Hdu 2082 find a word (primary function)
Search for wordsTime Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 4971 Accepted Submission (s): 3537
Problem Description assume there are x1 letters A and x2 letters B ,..... assume that the value of letter A is 1, and the value of letter B is 2 ,..... the value of Z is 26. How many words <= 50 can be found for a given letter? The value of a word is the sum of the values of all the letters of a word. For example, the value of word ACM is 1 + 3 + 14 = 18, the value of HDU is 8 + 4 + 21 = 33. (The words are irrelevant to the order. For example, ACM and CMA think they are the same word ).
Input is an integer N, which represents the number of test instances.
Then there are N rows of data. Each row contains 26 <= 20 integers x1, x2,... x26.
Output for each test instance, please Output the total value <= 50 words, each instance Output occupies a line.
Sample Input
21 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 09 2 6 2 10 2 2 5 6 1 0 2 7 0 2 2 7 5 10 6 10 2 10 6 1 9
Sample Output
7379297
Source
/1/15 ACM Program Design Final Examination
The master function template is distorted and easy to understand. I want my friends to understand what I understand.
If you understand something wrong
, 28
# Include
# Include
Int a [30], x [55], y [55]; int main () {int t, I, j, k; scanf ("% d ", & t); while (t --) {memset (x, 0, sizeof (x )); // The array x stores the number of memset (y, 0, sizeof (y) Combinations whose values are not greater than 50 )); // for (I = 1; I <= 26; I ++) scanf ("% d", & a [I]); for (I = 0; I <51 & I <= a [1]; I ++) // number of values 1 x [I] = 1; // If you only use a number with a value of 1 to represent the value I, then x [I] is initialized to 1 for (I = 2; I <= 26; I ++) {// I indicates the I-th expression. The above 1 has been saved, so from 2 for (j = 0; j <= 50; j ++) {// j indicates the j variable in the expression after the I expression is tired (k = 0; k + j <= 50 & k <= a [I] * I; k + = I) // k indicates the I-th index y [k + j] + = x [j]; // I has a [I] index at most, so k is a [I] * I} for (j = 0; j <51; j ++) {x [j] = y [j]; y [j] = 0 ;}} int sum = 0; for (I = 1; I <= 50; I ++) sum + = x [I]; printf ("% d \ n", sum);} return 0 ;}