杭電ACM hdu 1085 Holding Bin-Laden Captive! 解題報告(母函式)
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
Solution
以下部分的版權歸本人(小飛)所有。所有權利保留。
歡迎轉載,轉載時請註明出處:
http://blog.csdn.net/xiaofei_it/article/details/17041467
本題直接套用母函式模板即可。關於母函式的詳細解釋請看:
http://blog.csdn.net/xiaofei_it/article/details/17042651
程式碼如下:
#include <iostream>
#include <cstring>
using namespace std;
int n[3],a[9000],b[9000],i,j,k,last,last2;
int v[3]={1,2,5};
int main()
{
while ((cin>>n[0]>>n[1]>>n[2])&&(n[0]!=0||n[1]!=0|n[2]!=0))
{
a[0]=1;
last=0;
for (i=0;i<=2;i++)
{
last2=last+n[i]*v[i];
memset(b,0,sizeof(int)*(last2+1));
for (j=0;j<=n[i];j++)
for (k=0;k<=last;k++)
b[k+j*v[i]]+=a[k];
memcpy(a,b,sizeof(int)*(last2+1));
last=last2;
}
for (i=0;i<=last;i++)
if (a[i]==0)
break;
cout<<i<<endl;
}
return 0;
}
相關文章
- HDU 母函式簡單題 - 找單詞/Ignatius and the Princess III/Square Coins/Holding Bin-Laden Captive!函式APT
- HDU 1709 The Balance(母函式)函式
- 杭電OJ1040解題報告
- 杭電hdu2072
- 杭電HDU2018 奶牛的故事
- (補題 杭電 1008)Elevator
- 杭電多校補題
- HDU-ACM 2024 Day3ACM
- HDU-ACM 2024 Day4ACM
- HDU-ACM 2024 Day2ACM
- 2020-10-30 ACM實踐報告部分程式題ACM
- HDU 1848 Fibonacci again and again(SG函式)AI函式
- HDU 不要62 題解
- HDU - 5879解題文件
- 杭電2046
- 清科觀察:2018年母基金報告
- 杭電oj 2020
- 杭電No2000
- 2019山東ACM省賽補題題解ACM
- 【記憶優化搜尋/dp】HDU - 6415 - 杭電多校第九場 - Rikka with Nash Equilibrium優化UI
- HDU 6311 - Cover [2018杭電多校聯賽第二場 C](尤拉通路/迴路)
- HDU 1848 Fibonacci again and again (尼姆博弈+sg函式)AI函式
- [熵值] 解題報告熵
- 杭電2048(遞推)
- (杭電1406)完數
- 『杭電1810』Rating of Tetris
- 『杭電1940』ICPC Scoreboard
- 『杭電1939』He is offside!IDE
- 『杭電1937』Finding Seats
- HDU 5795 A Simple Nim (SG函式+打表找規律)函式
- HDU100題簡要題解(2080~2089)
- ARC173 解題報告
- P11188 解題報告
- SP30906 解題報告
- P10499 解題報告
- Reddit:2023年母親節朋友圈報告
- 尼爾森:2020母嬰消費洞察報告
- acm訓練題ACM
- MPA:2019年電影主題報告