跟上题是一个思路:http://www.cnblogs.com/whatbeg/p/3728545.html
只不过是上一题的扩展。
代码:
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define N 6807 int c[N],tc[N]; int main() { int val[27],num[27]; int i,j,k,t; for(i=1;i<=26;i++) val[i] = i; scanf("%d",&t); while(t--) { int maxi = 0; for(i=1;i<=26;i++) { scanf("%d",&num[i]); maxi += num[i] * val[i]; } for(i=0;i<6510;i++) c[i] = 0,tc[i] = 0; for(i=0;i<=val[1]*num[1];i+=val[1]) c[i] = 1; for(i=2;i<=26;i++) { for(j=0;j<=maxi;j++) { for(k=0;k+j<=maxi && k<=val[i]*num[i];k+=val[i]) tc[k+j] += c[j]; } for(j=0;j<=maxi;j++) { c[j] = tc[j]; tc[j] = 0; } } int sum = 0; for(i=1;i<=50;i++) sum += c[i]; printf("%d ",sum); } return 0; }