【HDOJ 1085】數學問題,母函數

來源:互聯網
上載者:User

標籤:

Holding Bin-Laden Captive!

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 17327    Accepted Submission(s): 7764


Problem DescriptionWe 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! 

 

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 is not to be processed. 

 

OutputOutput the minimum positive value that one cannot pay with given coins, one line for one case. 

 

Sample Input1 1 3 0 0 0 

 

Sample Output4 

 

Authorlcy   
#include<iostream>#include<algorithm>using namespace std;int main(){    int a,b,c;    while( cin >> a >> b >> c,a,b,c)    {        if(a >= 4 || (a >= 2 && b >=1) || (a >= 1 && b >= 2))        {            cout << a + b * 2 + c * 5 + 1 << endl;            continue;        }        if(a == 0)            cout << "1" << endl;        else if(b == 0)            cout << a + 1 << endl;        else if(a == 1 && b == 1)            cout << "4" << endl;    }    return 0;}

 

 

#include <iostream>#include <memory.h>#define N 8000using namespace std;int num[4];int c1[N+10],c2[N+10];int main(){    int i,j,k;    int value[4]= {0,1,2,5};    while(cin>>num[1]>>num[2]>>num[3])    {        if(num[1]==0&&num[2]==0&&num[3]==0)            return 0;        int n=0;        for(i=1;i<=3;i++)            n+=num[i]*value[i];        memset(c1,0,sizeof(c1));        memset(c2,0,sizeof(c2));        c1[0]=1;        for (i=1; i<=3; i++)        {            for (j=0; j<=n; j++)                for (k=0; k*value[i]+j<=n&&k<=num[i]; k++)                {                    c2[j+k*value[i]]+=c1[j];                }            for (j=0; j<=n; j++)            {                c1[j]=c2[j];                c2[j]=0;            }        }        int s;        for(s=1;s<=n;s++)        {            if(c1[s]==0)                break;        }        cout<<s<<endl;    }    return 0;}

 

 

【HDOJ 1085】數學問題,母函數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.