首页 > 代码库 > hdu 1085(普通母函数)
hdu 1085(普通母函数)
Holding Bin-Laden Captive!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 21240 Accepted Submission(s): 9420
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!
“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、
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<queue> 7 #include<map> 8 #include<set> 9 #include<vector> 10 #include<cstdlib> 11 #include<string> 12 #define eps 0.000000001 13 typedef long long ll; 14 typedef unsigned long long LL; 15 using namespace std; 16 const int N=10000+100; 17 int a[N]; 18 int c1[N],c2[N]; 19 int main(){ 20 int t[N]={0,1,2,5};; 21 while(scanf("%d%d%d",&a[1],&a[2],&a[3])!=EOF){ 22 if(a[1]==0&&a[2]==0&&a[3]==0)break; 23 int maxx=a[1]*1+a[2]*2+a[3]*5; 24 memset(c2,0,sizeof(c2)); 25 memset(c1,0,sizeof(c1)); 26 for(int i=0;i<=a[1];i++)c1[i]=1; 27 for(int i=2;i<=3;i++){ 28 for(int j=0;j<=maxx;j++) 29 for(int k=0;k<=a[i]*t[i]&&k+j<=maxx;k=k+t[i]){ 30 c2[j+k]=c2[j+k]+c1[j]; 31 } 32 for(int j=0;j<=maxx;j++){ 33 c1[j]=c2[j]; 34 c2[j]=0; 35 36 } 37 } 38 for(int i=0;i<=maxx+5;i++){ 39 if(c1[i]==0){ 40 cout<<i<<endl; 41 break; 42 } 43 44 } 45 } 46 }
hdu 1085(普通母函数)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。