2 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9 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
7 379297
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=2082
ACcode:
#include<cstdio> #include<cstring> #include<cmath> #define mem(a, b) memset(a, (b), sizeof(a)) #define Wi(a) while(a--) #define Si(a) scanf("%d", &a) #define Pi(a) printf("%d\n", (a)) int c1[55], c2[55]; int main(){ int t; int a[27] = {0}; Si(t); Wi(t) { int i, j, k; for(i = 1; i < 27; i++) Si(a[i]); mem(c1, 0); mem(c2, 0); int sum = 0; for(i = 0; i<51 && i<=a[1]; i++)//把c1初始化为1 c1[i] = 1; for(i = 2; i <= 26; i++)// i从2到n遍历,这里i就是指第i个表达式 { for(j = 0; j < 51; j++)// j从0到n遍历这里j就是前面i个表达式累乘的表达式里第j个变量 { for(k = 0; k+j<51&&k <= a[i]*i; k+=i)// k表示的是第j个指数,所以k每次增i(因为第i个表达式的增量是i) c2[k+j] += c1[j]; } for(j = 0; j < 51; j++)// 把c2的值赋给c1,而把c2初始化为0,因为c2每次是从一个表达式中开始的 { c1[j] = c2[j]; c2[j] = 0; } } for(i = 1; i <= 50; i++) sum += c1[i]; Pi(sum); } return 0; }