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;
    }
    
    
    
     

  • 相关阅读:
    ssh无密码登录设置
    Spark Standalone Mode 多机启动 -- 分布式计算系统spark学习(二)(更新一键启动slavers)
    Spark Standalone Mode 单机启动Spark -- 分布式计算系统spark学习(一)
    为golang程序使用pprof远程查看httpserver运行堆栈,cpu耗时等信息
    golang官方实现如何对httpserver做频率限制(最大连接数限制)
    【转】涨姿势了,数据库隔离性的几个级别
    loadRunner 11.0 安装及破解
    EF 如何code first
    百度搜索自动提示搜索相关内容----模拟实现
    如何写出专业级OOP程序-----文档注释
  • 原文地址:https://www.cnblogs.com/hua-dong/p/7603923.html
Copyright © 2011-2022 走看看