Problem Description
We all know this bin-laden is a notorious terrorist, and he have disappeared for a long time. But recently, it's reported that he hides in hang Zhou of china!
"Oh, god! How terrible! ”
Don ' t is so afraid, guys. Although he hides in a cave of the Hang Zhou, the He dares not the go out. Laden is so bored recent years that he fling himself to some math problems, and he said that if anyone can solve his pro Blem, he'll give himself up!
ha-ha! Obviously, Laden is too proud of he intelligence! But, what's his problem?
"Given some Chinese Coins (coins) (three kinds--1, 2, 5), and their number is num_1, num_2 and num_5 respectively, please OU Tput the minimum value that's 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 are 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 30) 0 0
Sample Output
4
Author
Lcy
A simple template of the female function, although very simple, but it is very interesting to do this problem, I wrote many times, are timed out
Until I got a puzzle on the internet .....
The first piece of code I wrote, the sheer set of templates,
The second code is on-line grilled, found that people write is very flexible,
I want to reflect on the reflection, after writing the topic can not be too rigid, to flexible processing. In addition, the premise of being able to deal flexibly is that the understanding is deep enough, so the knowledge point should be carefully understood
#include <bits/stdc++.h>using namespacestd;Const intmaxn=500000;intnum[6];intA[MAXN],C[MAXN];intsolve () { for(intI=0; i<=num[1];i++) {A[i]=1; C[i]=0; } memset (c,0,sizeof(c)); intI=0; while(1){ if(i==2|| i==5){ for(intj=0; j<=maxn;j++){ for(intk=0; k<=num[i]*i;k+=i) {C[k+j]+=A[j]; } } for(intj=0; j<=maxn;j++) {A[j]=C[j]; C[J]=0; } } if(i==6) { Break;} Elsei++; } for(intI=1; i<maxn;i++){ if(a[i]==0)returni; }}voidprint () { for(intI=0; i<num[5]*5; i++) {cout<<a[i]<<Endl; }}intMain () { while(cin>>num[1]>>num[2]>>num[5]){ if(num[1]==0&&num[2]==0&&num[5]==0){ Break; } cout<<solve () <<Endl; //print ();memset (NUM,0,sizeof(num)); }}
#include <cstdio>#include<cstring>#defineM 8005intVIS[M];//the number of tokens that can be combined;intMain () {intnum_1,num_2,num_5; while(true) {scanf (" %d%d%d",&num_1,&num_2,&num_5); if(num_1 + num_2 + num_5 = =0) Break; memset (Vis,0,sizeof(VIS)); for(inti =0; I <= num_1; i++) Vis[i]=1; for(intj =0; J <= Num_2 *2; J + =2) { for(intK =0; K <= Num_1; k++) {vis[j+ K] =1; } } for(intj =0; J <= Num_5 *5; J + =5) { for(intK =0; K <= num_1 + num_2 *2; k++) { if(Vis[k])//If the current number can be combined, then add;{vis[k+ j] =1; } } } inti; for(i =1; I <= num_1 + num_2 *2+ Num_5 *5; i++) { if(Vis[i] = =0) { Break; }} printf ("%d\n", i); } return 0;}
Hdu--1085--holding Bin-laden captive! (female function)