杭電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;
}
相關文章
- 杭電ACM hdu 2152 Fruit 解題報告(母函式)ACMUI函式
- 杭電ACM hdu 2110 Crisis of HDU 解題報告(母函式)ACM函式
- 杭電ACM hdu 1398 Square Coins 解題報告(母函式)ACM函式
- 杭電ACM hdu 1171 Big Event in HDU 解題報告(母函式)ACM函式
- 杭電ACM hdu 2082 找單詞 解題報告(母函式)ACM函式
- 杭電ACM hdu 2079 選課時間 解題報告(母函式)ACM函式
- HDU 母函式簡單題 - 找單詞/Ignatius and the Princess III/Square Coins/Holding Bin-Laden Captive!函式APT
- HDU 1709 The Balance(母函式)函式
- 母函式詳解和史上最通用最高效的母函式模板函式
- HDU 1028 Ignatius and the Princess III:dp or 母函式函式
- HDU 2082-找單詞(母函式-有限次)函式
- NYNU ACM 藍橋杯選拔賽 解題報告ACM
- 山東省第四屆acm解題報告(部分)ACM
- Java 杭電ACM Train Problem I 1022JavaACMAI
- 杭電多校補題
- YT03-遞推求解課堂題目-1003 獻給杭電五十週年校慶的禮物-(6.7日-煙臺大學ACM預備隊解題報告)ACM
- HDU 1028-Ignatius and the Princess III(拆分整數-母函式-無限次)函式
- 河南理工大學程式設計(ACM)大賽解題報告程式設計ACM
- SG 函式初步 HDU 1536 && HDU 1944函式
- HDOJ-1398 Square Coins(母函式)函式
- HDU2588GCD(尤拉函式)GC函式
- [熵值] 解題報告熵
- ACM HDU 1279 驗證角谷猜想(簡單水題)ACM
- 2020-10-30 ACM實踐報告部分程式題ACM
- HDU1729 Stone Game (SG函式)GAM函式
- 報告彙總資料使用組函式函式
- HDU 不要62 題解
- ARC173 解題報告
- HDU 4002Find the maximum(尤拉函式)函式
- HDU杭電1874-暢通工程續(dijkstra演算法和Floyd演算法)演算法
- HDU-ACM 2024 Day2ACM
- HDU-ACM 2024 Day3ACM
- HDU-ACM 2024 Day4ACM
- 『杭電1939』He is offside!IDE
- 科大訊飛大資料:新母嬰人群洞察報告大資料
- YT06-揹包-1001—Bone Collector -(6.27日-煙臺大學ACM預備隊解題報告)ACM
- 【記憶優化搜尋/dp】HDU - 6415 - 杭電多校第九場 - Rikka with Nash Equilibrium優化UI
- CF720B 解題報告