标签:
题目链接:
http://acm.nefu.edu.cn/JudgeOnline/problemshow.php?problem_id=776
题目大意:
给你面值为1分、2分、5分的硬币,并且这些硬币的数量分别为N1,N2和N5。问:
这些硬币最小不能表示的值为多少。
思路:
母函数问题,通过分析,可得:
g(x) = (1+x+x^2+x^3+…+x^N1) * (1+x^2+x^4+…x^(2*N2) ) * (1+x^5+x^10+…x^(5*N5) )
这些硬币能表示的最大值Max = N1 + N2*2 + N5*5。考虑1,2,…,Max,Max+1次幂的系数是
否为令,找出这些硬币不能表示的最小的值。
AC代码:
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> using namespace std; int c1[10010],c2[10010]; int main() { int N1,N2,N5; while(cin >> N1 >> N2 >> N5 && (N1||N2||N5)) { memset(c1,0,sizeof(c1)); memset(c2,0,sizeof(c2)); for(int i = 0; i <= N1; ++i) c1[i] = 1; for(int i = 0; i <= N1; ++i) for(int j = 0; j <= N2; ++j) c2[i+2*j] += c1[i]; for(int i = 0; i <= N1+N2*2; ++i) { c1[i] = c2[i]; c2[i] = 0; } for(int i = 0; i <= N1+N2*2; ++i) for(int j = 0; j <= N5; ++j) c2[i+5*j] += c1[i]; for(int i = 0; i <= N1+N2*2+N5*5; ++i) c1[i] = c2[i]; for(int i = 0; i <= N1+N2*2+N5*5+1; ++i) if(c1[i] == 0) { cout << i << endl; break; } } return 0; }
标签:
原文地址:http://blog.csdn.net/lianai911/article/details/45739985