hdu 2082 找单词
hdu2082找单词
构造幂为价值的生成函数
#include<cstdio>
#include<cstring>
#include<algorithm>
inline int read() {
int x = 0;
char c = getchar();
while(c < '0' || c > '9') c = getchar();
while(c <= '9' && c >= '0')x = x * 10 + c- '0',c = getchar();
return x ;
}
const int maxn = 60;
int k,a[maxn],b[maxn];
int main() {
k = read();
while(k --) {
int num;
memset(b,0,sizeof b);
memset(a,0,sizeof a);
a[0] = 1;
for(int i = 1;i <= 26;++ i) {
num = read();
if(!num) continue;
for(int j = 0;j <= 50;++ j) {
for(int k = 0;k <= num && k * i + j <= 50;++ k)
b[k * i + j] += a[j];
}
for(int j = 0;j <= 50;++ j) a[j] = b[j],b[j] = 0;
}
int ans = 0;
for(int i = 1;i <= 50;++ i) ans += a[i];
printf("%d\n",ans);
}
return 0;
}