hdu 2079

经典的母函数题,刚开始还想用回溯做,查了网络才知道是用母函数做,

以前做过好几道母函数的题目还有一些印象知道如何写,最后果断AC

/* Author: ACb0y Date:2010年9月6日20:18:52 Type:母函数 ProblemId: hdu 2079 选课时间(题目已修改,注意读题) Result: 2925387 2010-09-06 20:18:25 Accepted 2079 15MS 272K 668 B C++ ACb0y */ #include <iostream> using namespace std; int credit[10]; int Count[10]; int c1[50], c2[50]; int main() { int T; #ifndef ONLINE_JUDGE freopen("2079.txt", "r", stdin); #endif cin >> T; while (T--) { int i, j, k; int n, K; cin >> n >> K; for (i = 1; i <= K; i++) { cin >> credit[i] >> Count[i]; } memset(c1, 0, sizeof(c1)); memset(c2, 0, sizeof(c2)); c1[0] = 1; for (i = 1; i <= K; i++) { for (j = 0; j <= n; j++) { for (k = 0; k <= Count[i] && credit[i] * k + j <= n; k++) { c2[credit[i] * k + j] += c1[j]; } } memcpy(c1, c2, sizeof(c1)); memset(c2, 0, sizeof(c2)); } cout << c1[n] << endl; } return 0; }

你可能感兴趣的:(c,网络,2010)