【HDU 1085】【母函数】Holding Bin-Laden Captive!【给你a1个一元硬币,a2个两元硬币,a3个五元硬币,问不能凑出来的第一个面额是多少】
2016-10-23 22:52
369 查看
传送门:http://acm.split.hdu.edu.cn/showproblem.php?pid=1085
描述:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 20783 Accepted Submission(s): 9232
Problem Description
We all know that Bin-Laden is a notorious terrorist, and he has disappeared for a long time. But recently, it is reported that he hides in Hang Zhou of China!
“Oh, God! How terrible! ”
Don’t be so afraid, guys. Although he hides in a cave of Hang Zhou, he dares not to go out. Laden is so bored recent years that he fling himself into some math problems, and he said that if anyone can solve his problem, he will give himself up!
Ha-ha! Obviously, Laden is too proud of his intelligence! But, what is his problem?
“Given some Chinese Coins (硬币) (three kinds-- 1, 2, 5), and their number is num_1, num_2 and num_5 respectively, please output the minimum value that you cannot pay with given coins.”
You, super ACMer, should solve the problem easily, and don’t forget to take $25000000 from Bush!
Input
Input contains multiple test cases. Each test case contains 3 positive integers num_1, num_2 and num_5 (0<=num_i<=1000). A test case containing 0 0 0 terminates the input and this test case is not to be processed.
Output
Output the minimum positive value that one cannot pay with given coins, one line for one case.
Sample Input
1 1 3
0 0 0
Sample Output
4
Author
lcy
Recommend
We have carefully selected several similar problems for you: 2152 2082 1709 2079 2110
题意:
给你a1个一元硬币,a2个两元硬币,a3个五元硬币,问不能凑出来的第一个面额是多少。
思路:
母函数,公式为
(1+x+x^2+x^3+.........x^a1)∗(1+x^2+x^4+x^6+.........x^a2)∗(1+x^5+x^10+x^15+............x^a5)
直接模拟即可。
代码:
描述:
Holding Bin-Laden Captive!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 20783 Accepted Submission(s): 9232
Problem Description
We all know that Bin-Laden is a notorious terrorist, and he has disappeared for a long time. But recently, it is reported that he hides in Hang Zhou of China!
“Oh, God! How terrible! ”
Don’t be so afraid, guys. Although he hides in a cave of Hang Zhou, he dares not to go out. Laden is so bored recent years that he fling himself into some math problems, and he said that if anyone can solve his problem, he will give himself up!
Ha-ha! Obviously, Laden is too proud of his intelligence! But, what is his problem?
“Given some Chinese Coins (硬币) (three kinds-- 1, 2, 5), and their number is num_1, num_2 and num_5 respectively, please output the minimum value that you cannot pay with given coins.”
You, super ACMer, should solve the problem easily, and don’t forget to take $25000000 from Bush!
Input
Input contains multiple test cases. Each test case contains 3 positive integers num_1, num_2 and num_5 (0<=num_i<=1000). A test case containing 0 0 0 terminates the input and this test case is not to be processed.
Output
Output the minimum positive value that one cannot pay with given coins, one line for one case.
Sample Input
1 1 3
0 0 0
Sample Output
4
Author
lcy
Recommend
We have carefully selected several similar problems for you: 2152 2082 1709 2079 2110
题意:
给你a1个一元硬币,a2个两元硬币,a3个五元硬币,问不能凑出来的第一个面额是多少。
思路:
母函数,公式为
(1+x+x^2+x^3+.........x^a1)∗(1+x^2+x^4+x^6+.........x^a2)∗(1+x^5+x^10+x^15+............x^a5)
直接模拟即可。
代码:
#include <bits/stdc++.h> using namespace std; #define mst(ss,b) memset(ss,b,sizeof(ss)); #define rep(i,k,n) for(int i=k;i<=n;i++) const int N=10000; int c1 , c2 , mx; int a[3], val[3] = {1, 2, 5}; int cal(){ mst(c1, 0); mst(c2, 0); mx=0; rep(i, 0, 2){ mx += a[i] * val[i];// 可能组成的最大值 } rep(i, 0, a[0]){//先处理第一种硬币 c1[i] = 1; } rep(i, 1, 2){ // 对于1后面的每种硬币 rep(j, 0, mx)if(c1[j]){ //枚举已知范围 for(int k = 0; k <= a[i] * val[i]; k += val[i]){//枚举新增范围 if(j + k <= mx) c2[j + k] += c1[j]; } } // 把当前项保存在c1,清空c2 memcpy(c1, c2, sizeof(c1)); mst(c2, 0); } rep(i, 1, mx)if(!c1[i])return i; } int main(){ while(~scanf("%d%d%d", &a[0], &a[1], &a[2]), a[0] + a[1] + a[2]){ printf("%d\n", cal()); } return 0; }
相关文章推荐
- hdu 1085 Holding Bin-Laden Captive! (母函数)
- HDU 1085 Holding Bin-Laden Captive! 母函数||背包||递推
- HDU 1085 Holding Bin-Laden Captive! 母函数
- HDU 1085 Holding Bin-Laden Captive!(母函数)
- HDU 1085 Holding Bin-Laden Captive! 【母函数】
- 母函数 HDU 1085 Holding Bin-Laden Captive!
- hdu 1085 Holding Bin-Laden Captive!(母函数)
- hdu 1085 Holding Bin-Laden Captive! (母函数)
- HDU 1085 Holding Bin-Laden Captive!(母函数)
- hdu 1085 Holding Bin-Laden Captive! 母函数
- HDU 1085 Holding Bin-Laden Captive! (母函数)
- [ACM] hdu 1085 Holding Bin-Laden Captive! (母函数变形)
- HDU 1085-Holding Bin-Laden Captive!(母函数)
- HDOJ/HDU 1085 母函数 Holding Bin-Laden Captive!
- [母函数]HDU 1085 Holding Bin-Laden Captive!
- [ACM] hdu 1085 Holding Bin-Laden Captive! (母函数变形)
- hdu1085 Holding Bin-Laden Captive!(母函数)
- HDU 1085 Holding Bin-Laden Captive! 活捉本拉登(普通型母函数)
- HDU 1085 Holding Bin-Laden Captive! 母函数③
- HDU 1085 Holding Bin-Laden Captive! 母函数