HDOJ 2082 生成函数
链接:
http://acm.hdu.edu.cn/showproblem.php?pid=2082
代码:
31 int n, k; 32 int v[30], m[30]; 33 int a[10010], b[10010], last; 34 35 int main() { 36 ios::sync_with_stdio(false), cin.tie(0); 37 int T; 38 cin >> T; 39 while (T--) { 40 rep(i, 0, 26) { 41 v[i] = i + 1; 42 cin >> m[i]; 43 } 44 a[0] = 1; 45 last = 0; 46 rep(i, 0, 26) { 47 int last2 = last + v[i] * m[i]; 48 memset(b, 0, sizeof(b)); 49 rep(j, 0, m[i] + 1) rep(k, 0, last + 1) 50 b[k + j*v[i]] += a[k]; 51 memcpy(a, b, sizeof(b)); 52 last = last2; 53 } 54 int ans = 0; 55 rep(i, 1, 51) ans += a[i]; 56 cout << ans << endl; 57 } 58 return 0; 59 }