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#include<string.h> #include<stdio.h> int ans[55]; int c1[100], c2[100]; int main() { int a[27], t, i, j, k; scanf("%d", &t); while(t --){ memset(c1, 0, sizeof(c1)); //初始化 memset(c2, 0, sizeof(c2)); c1[0]=1; for(i = 1; i <= 26; i ++){ scanf("%d", &a[i]); // if(a[i] == 0){ //跳过数目为0的 // continue; // } for(j = 0; j <= 50; j ++) { for(k = 0; j+k <= 50&&k<=a[i]*i; k += i) { //这里的k <= a[i]*i, 意思是表示a[i]个价值为i的字母的组成的最大价值 c2[j+k] += c1[j]; } } for(j = 0; j <= 50; j ++) { c1[j] = c2[j]; c2[j] = 0; } } int ans= 0; for(i = 1; i <= 50; i ++){ ans+= c1[i]; } printf("%d\n", ans); } return 0; }
原文地址:http://blog.csdn.net/holyang_1013197377/article/details/40345935