HDU 1085-holding Bin-laden captive! (build function)

Source: Internet
Author: User

Holding Bin-laden captive!Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 15384 Accepted Submission (s): 6892


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 is still the female function water over. Test instructions: 3 denominations of Coins {1,2,5} now give the number of these 3 kinds of coins, the smallest can not be composed of the face value.

Brute force generation a[] array sweep over the first 0 is the minimum value that cannot be formed

 #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <cctype># Include <cmath> #include <cstdlib> #include <vector> #include <queue> #include <set># Include <map> #include <list> #define MAXN 100100#define ll long long#define INF 0x3f3f3f3f#define pp pair<i Nt,int>using namespace Std;int a[maxn],b[maxn],v[3]={1,2,5},p,n[3];void solve () {P=n[0]+n[1]*2+n[2]*5;memset (a,0 , sizeof (a)); a[0]=1;for (int i=0;i<3;i++) {memset (b,0,sizeof (b)); for (int j=0;j<=n[i]&&j*v[i]<=p;j+ +) for (int k=0;k+j*v[i]<=p;k++) b[k+j*v[i]]+=a[k];memcpy (a,b,sizeof (b));} int Ans;for (Ans=0;ans<=p;++ans) if (a[ans]==0) break;printf ("%d\n", ans);} int main () {while (~scanf ("%d%d%d", &n[0],&n[1],&n[2])} {if (!n[0]&&!n[1]&&!n[2]) break; Solve ();} return 0;} 

Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

HDU 1085-holding Bin-laden captive! (build function)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.