HDU_1284 钱币兑换问题(生成函数)

  先打表,否则TLE

My Code:

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

using namespace std;

const int N = 32767;

int c1[N+1], c2[N+1];

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

int n, i, j, k;

for(i = 0; i <= N; i++) {
c1[i] = 1; c2[i] = 0;
}
for(i = 2; i <= 3; i++) {
for(j = 0; j <= N; j++) {
for(k = 0; k + j <= N; k += i)
c2[k+j] += c1[j];
}
for(j = 0; j <= N; j++) {
c1[j] = c2[j]; c2[j] = 0;
}
}

while(~scanf("%d", &n)) {
cout << c1[n] << endl;
}
return 0;
}



原文地址:https://www.cnblogs.com/vongang/p/2264537.html