Holding Bin-laden captive!
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 16548 Accepted Submission (s): 7436
Problem descriptionwe 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!
Inputinput 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.
Outputoutput 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
Authorlcy
after learning the mother function after the first hand, so that only really understand the meaning of the algorithm will knock him out and according to the specific requirements of the topic to learn the flexibility to pass. The same is the expression of the female function, and then the triple loop, the polynomial multiplication, to determine which exponent from the 0 increase in the process, which is the coefficient of 0. This is what is asked, but there is a WA particularly strong several times, each time the initialization of two arrays, it is necessary to save the final factor result of the array of the last subscript value plus one of the elements set to 0;
#include <iostream>const int m=100000; #include <algorithm>using namespace Std;int Main () {int i,j,k,n1,n2,n5,cnt[m],dic[m]; while (CIN>>N1>>N2>>N5,N1+N2+N5) {int min=n1+2*n2+5*n5; for (int h=0; h<=min; h++) {cnt[h]=1; dic[h]=0; } cnt[min+1]=0; for (j=0; j<=n1; j + +) for (k=0; k<=2*n2; k+=2) {dic[j+k]+=cnt[j]; } for (int p=0; p<=2*n2+n1; p++) {cnt[p]=dic[p]; dic[p]=0; } for (j=0; j<=2*n2+n1; j + +) for (k=0; k<=5*n5; k+=5) {dic[j+k]+=cnt[j]; } for (int e=0; e<=min; e++) {cnt[e]=dic[e]; dic[e]=0; } for (int q=0;; q++) {if (!cnt[q]) {
cout<<q<<endl; Break ; }}} return 0;}
Hangzhou Electric HDU ACM 1085 Holding Bin-laden captive!