HDU_2082 找单词 (生成函数)

  很裸的生成函数:

My Code:

#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

const int N = 100;

int c1[N], c2[N];
int val[N];

int main() {
//freopen("data.in", "r", stdin);

int i, j, k, t, ans;
while(~scanf("%d", &t)) {
while(t--) {
for(i = 1; i <= 26; i++)
scanf("%d", &val[i]);
memset(c1, 0, sizeof(c1));
memset(c2, 0, sizeof(c2));
for(i = 0; i <= 50 && i <= val[1]; i++) {
c1[i] = 1;
}
for(i = 2; i <= 26; i++) {
for(j = 0; j <= 50; j++) {
for(k = 0; k + j <= 50 && k <= i*val[i]; k += i) {
c2[j + k] += c1[j];
}
}
for(j = 0; j <= 50; j++) {
c1[j] = c2[j]; c2[j] = 0;
}
}
for(ans = 0, i = 1; i <= 50; i++) {
ans += c1[i];
}
cout << ans << endl;
}
}
return 0;
}



你可能感兴趣的:(HDU)