zoukankan      html  css  js  c++  java
  • HDU1085 多重背包

                                          Holding Bin-Laden Captive!

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

    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!

     

    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

    
    
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<iostream>
    #include<string>
    #include<memory.h>
    #include<algorithm>
    #include<map>
    #include<queue>
    using namespace std;
    int m[8010],m2[30];
    int n1,n2,n3,s,Max,tmp,L,i,j;
    void _work()
    {
        tmp=1;
            while(n1>0) {
                if(n1>=tmp) m2[++L]=1*tmp;
                else m2[++L]=1*n1;
                n1-=tmp;
                tmp*=2;
            }
            tmp=1;
            while(n2>0) {
                if(n2>=tmp) m2[++L]=2*tmp;
                else m2[++L]=2*n2;
                n2-=tmp;
                tmp*=2;
            }
            tmp=1;
            while(n3>0) {
                if(n3>=tmp) m2[++L]=5*tmp;
                else m2[++L]=5*n3;
                n3-=tmp;
                tmp*=2;
            }
    }
    int main()
    {
        while(~scanf("%d%d%d",&n1,&n2,&n3)){    
            if(n1==0&&n2==0&&n3==0) return 0;
            L=0;
            Max=n1+n2*2+n3*5;
            memset(m,0,sizeof(m));
            m[0]=1;
            
            _work();
            for(i=1;i<=L;i++)
             for(j=Max;j>=1;j--)
                 if(j-m2[i]>=0&&m[j-m2[i]]==1) m[j]=1;
             for(i=0;i<=Max;i++)
              if(!m[i]) break;
             cout<<i<<endl;
        }
        return 0;
    }
    
    
    
     

  • 相关阅读:
    Spring经典视频教程大集合
    使用jsonlib进行Java和JSON之间的转换
    c:import Unable to get RequestDispatcher for Context
    打开IE都会弹出欢迎界面“欢迎使用Internet Explorer 8”
    Struts2 标签 用法示例 (
    as3相关的frameworks
    as相关的框架引擎应用集合
    init
    XNA框架基础——疑难解答
    XNA框架基础——XNA的注意事项
  • 原文地址:https://www.cnblogs.com/hua-dong/p/7603923.html
Copyright © 2011-2022 走看看