hdu 1085 Holding Bin-Laden Captive! (母函数)

原创 2018年04月16日 21:31:52

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 30 0 0
 

Sample Output
4
 

Author
lcy
 

Recommend
We have carefully selected several similar problems for you:  1171 2152 2082 1709 2079 
 

https://blog.csdn.net/dsaghjkye/article/details/79965837和这个题也差不多

题意:你有 a个1元,b个2元,c个5元 ,问你最小的不能正好支付的钱是多少

解:c1[i]=j代表的是组成i的方案有j种,c2的意义和c1相同,不过c2是再引入1个新的元素后,方案的变化,然后我们把c2的值赋给c1,c2重新归零

显然 我们第 1个元素是 1,他有 a个,那么 for(i,0,a)   c2[i] =1

第二个元素是 2  ,有 b 个  for(i,0,a)   for(j , 0, b)

0 :  c2[0]+=c1[0]         c2[0+(2*j)]+=c1[0]  .......  

1 :  c2[1]+=c1[1]           c2[ 1+(2*j)] +=c1[0] ........

.......

a :.......................

然后我们把c2的值赋给c1,清空c2

第 三个元素 是 5  ,有 c个  for(i, 0,a+ 2*b)  for( j ,0 , c)

0:     c2[0+(5*j)]+=c1[0] ......

..........

a+ 2*b  : ..........

#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<iostream>
#include<math.h>
#include<queue>
#include<map>
#include<vector>
#include<set>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
int c1[11330],c2[11330];
int num[5];
int a[12]={0,1,2,5};
int main()
{
    int n;
    while(~scanf("%d%d%d",&num[1],&num[2],&num[3])&&num[1]+num[2]+num[3])
    {
        memset(c2,0,sizeof(c2));
        memset(c1,0,sizeof(c1));
        for(int i=0;i<=num[1];i++)//1号元素
             c1[i]=1; 
        int ans=num[1]; 
        for(int i=2;i<=3;i++)//一共 3个元素
        {
            for(int j=0;j<=ans;j++) //到上一个元素能取得的最大值
            {
                for(int k=0;k<=num[i];k++) //当前元素的个数
                {
                    c2[j+k*a[i]]+=c1[j];  
                }
            }
            ans+=num[i]*a[i]; //最大值改变
            for(int j=0;j<=ans;j++) //c2赋给c1
                c1[j]=c2[j];
            memset(c2,0,sizeof(c2)); //c2 清空
        }
        int i;
       for(i=0;i<11300;i++)
       {
           if(c1[i]==0)
           {
               printf("%d\n",i);
               break;
            }
       }
    }
}

https://blog.csdn.net/dsaghjkye/article/details/79991792

#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<iostream>
#include<math.h>
#include<queue>
#include<map>
#include<vector>
#include<set>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
int v[3511330];
int w[11];
int a[10]={0,1,2,5};
int main()
{
    int yy=1;
 while(~scanf("%d%d%d",&w[1],&w[2],&w[3])&&w[1]+w[2]+w[3])
 {
     int sum=0;
     for(int i=1;i<=3;i++)
         sum+=w[i]*a[i];
     memset(v,0,sizeof(v));
     v[0]=1;
    for(int i=1;i<=3;i++)
    {
        for(int j=1;w[i];j=j<<1)
        {
            int u=a[i]*(j<=w[i]?j:w[i]);
            for(int k=sum;k>=u;k--)
            {
                if(v[k-u]) v[k]=1;
            }
            if(j>w[i]) break;
            w[i]-=j;
        }
    }
     for(int i=1;i<=sum+1;i++)
     {
        if(v[i]==0)
         {
             printf("%d\n",i);
             break;
         }
     }
 }
}






版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/dsaghjkye/article/details/79966728

杭电ACM hdu 1085 Holding Bin-Laden Captive! 解题报告(母函数)

出处:http://acm.hdu.edu.cn/showproblem.php?pid=1085 Problem Description We all know that Bin-Laden is...
  • u012077163
  • u012077163
  • 2013-11-30 16:27:03
  • 2467

Holding Bin-Laden Captive!(母函数)

Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J...
  • ZSGG_ACM
  • ZSGG_ACM
  • 2014-08-31 22:55:05
  • 859

hdu 1085 Holding Bin-Laden Captive!(Java)

hdu 1085 Holding Bin-Laden Captive!(Java)
  • jwzdw123
  • jwzdw123
  • 2015-09-09 21:52:04
  • 222

杭电OJ——1085 Holding Bin-Laden Captive!(母函数解答!)

Holding Bin-Laden Captive! Problem Description We all know that Bin-Laden is a notorious t...
  • lishuhuakai
  • lishuhuakai
  • 2012-12-07 08:26:21
  • 2847

Holding Bin-Laden Captive! 1085 (母函数)

Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Ja...
  • yanghui07216
  • yanghui07216
  • 2015-09-08 21:14:23
  • 175

HDU 1085 Holding Bin-Laden Captive! (母函数)

题意:给定三中硬币,面值分别为1,2,5,并且给定三种硬币的数量分别为num_1,num_2,num_5,然后让求解这些硬币所不能组成的最小的面额是多少,例如给定的例子,面值为1的硬币为1枚,面值为2...
  • IAccepted
  • IAccepted
  • 2014-04-24 23:24:14
  • 2594

HDU -- 1085 Holding Bin-Laden Captive!(母函数)

题目大意:有三种硬币,1分,2分,5分,分别给出三种硬币的个数,问由这些硬币不能构成的最小值是多少。 代码实现: #include #include const int maxn=8050; int ...
  • u011346442
  • u011346442
  • 2015-02-08 22:18:28
  • 227

hdu 1085 Holding Bin-Laden Captive!(母函数/背包)

Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J...
  • acm_cxq
  • acm_cxq
  • 2016-10-15 21:56:06
  • 260

[hdu 1085] Holding Bin-Laden Captive!(母函数版)

题目大意是说,有1 2 5三种硬币,各有x[0] x[1] x[2]个
  • u014204710
  • u014204710
  • 2014-05-01 04:54:54
  • 658

HDU 1085 Holding Bin-Laden Captive!(母函数)

HDU 1085 Holding Bin-Laden Captive!(母函数) 题目地址 题意:  给你cnt1个一元硬币,cnt2个两元硬币,cnt3个五元硬币,问不能凑出来的第一个面额是多少...
  • hcbbt
  • hcbbt
  • 2014-05-25 22:50:45
  • 2203
收藏助手
不良信息举报
您举报文章:hdu 1085 Holding Bin-Laden Captive! (母函数)
举报原因:
原因补充:

(最多只允许输入30个字)