日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Holding Bin-Laden Captive! (HDU-1085)

發(fā)布時(shí)間:2025/3/17 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Holding Bin-Laden Captive! (HDU-1085) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

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

題意:每組給出 1 角、2 角、5 角硬幣的個(gè)數(shù) num1、num2、num5,問最小的不能組成的錢數(shù)

思路:普通母函數(shù)

根據(jù)題意,使用模版 2 較為方便,只需考慮 n2 數(shù)組的影響即可

首先 k=3,v[0]=1,v[1]=2,v[2]=3,n2[0]=num1,n2[1]=num2,n2[2]=num5,n1[0]=n1[1]=n1[2]=0

其次 P 可忽略,那么?last2 改為 last2=last+n[i]*v[i]

由于要求最小的不能組成錢數(shù),那么在跑完模版后,枚舉所有的冪次從 0?到 last,尋找 a[i]=0 的序號 i 即可。

Source Program

#include<iostream> #include<cstdio> #include<cstdlib> #include<string> #include<cstring> #include<cmath> #include<ctime> #include<algorithm> #include<utility> #include<stack> #include<queue> #include<vector> #include<set> #include<map> #define EPS 1e-9 #define PI acos(-1.0) #define INF 0x3f3f3f3f #define LL long long const int MOD = 1E9+7; const int N = 10000+5; const int dx[] = {0,0,-1,1,-1,-1,1,1}; const int dy[] = {-1,1,0,0,-1,1,-1,1}; using namespace std;int a[N];//權(quán)重為i的組合數(shù) int b[N];//臨時(shí)數(shù)組 int v[N],n1[N],n2[N]; int main(){v[0]=1;v[1]=2;v[2]=5;while(scanf("%d%d%d",&n2[0],&n2[1],&n2[2])!=EOF&&(n2[0]+n2[1]+n2[2])){a[0]=1;memset(n1,0,sizeof(n1));int last=0;for(int i=0; i<3; i++) { // int last2=min(last+n2[i]*v[i],P);//計(jì)算下一次的lastint last2=last+n2[i]*v[i];memset(b,0,sizeof(int)*(last2+1));//只清空b[0..last2]for(int j=n1[i]; j<=n2[i]&&j*v[i]<=last2; j++) //last2for(int k=0; k<=last&&k+j*v[i]<=last2; k++) //一個(gè)是last,一個(gè)是last2b[k+j*v[i]]+=a[k];memcpy(a,b,sizeof(int)*(last2+1));//b賦值給a,只賦值0..last2last=last2;//更新last}int i;for(i=0;i<=last;i++)if(a[i]==0)break;printf("%d\n",i);}return 0; }

?

總結(jié)

以上是生活随笔為你收集整理的Holding Bin-Laden Captive! (HDU-1085)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。