Skip to main content
  1. Posts/

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

·2 mins
Note: This article is available in Chinese only. 本文暂无英文版本。 View original

http://acm.hdu.edu.cn/showproblem.php?pid=1085 题意;一元的钱有num_1张,2元的钱有num_2张,5元的钱有num_5张,问最小的不能组成的钱是多少。 思路:有限个个数的母函数,并且不知道最好要多少,所以限制条件变成了不同种类钱的个数。统计0到num_1+2num_2+5num_5的方案数,第一个为0的就是答案。

20161117更新:之前贴的代码好像有点问题…估计是最后一次更新以后忘记保存了orz

 1/* ***********************************************
 2Author :111qqz
 3Created Time :2016年02月25日 星期四 22时26分16秒
 4File Name :code/hdu.1085.cpp
 5************************************************ */
 6
 7#include <cstdio>
 8#include <cstring>
 9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25#define pi pair < int ,int >
26#define MP make_pair
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33const int N=9E3+7;
34int num_1,num_2,num_5;
35int a[N],tmp[N];
36int main()
37{
38    #ifndef  ONLINE_JUDGE
39    freopen("code/in.txt","r",stdin);
40  #endif
41
42    while (~scanf("%d%d%d",&num_1,&num_2,&num_5))
43    {
44        if (num_1==0&&num_2==0&&num_5==0) break;
45        ms(a,0);
46        int total = num_1+2*num_2+5*num_5;
47        for ( int i = 0 ; i <= num_1; i++)
48        {
49        a[i] = 1;
50        tmp[i] = 0;
51        }
52
53        for ( int j = 0 ; j <= num_1 ; j++)
54        {
55        for ( int k =  0; k <=num_2 ; k++)
56        {
57            tmp[j+2*k] += a[j];
58        }
59        }
60
61        for ( int j = 0 ; j <= num_1 +2*num_2 ; j++)
62        {
63        a[j] = tmp[j];
64        tmp[j] = 0 ;
65        }
66
67        for ( int j = 0 ; j <= num_1+2*num_2 ; j++)
68        {
69        for ( int k =  0;  k <= num_5 ; k++)
70        {
71            tmp[j+5*k]+=a[j];
72        }
73        }
74        for ( int j = 0 ; j <= total ; j++)
75        {
76        a[j] = tmp[j];
77        tmp[j] =  0 ;
78        }
79
80        for ( int i = 0 ; i <= total +1 ; i ++)
81        {
82        if (a[i]==0)
83        {
84            printf("%d\n",i);
85            break;
86        }
87        }
88    }
89
90  #ifndef ONLINE_JUDGE
91  fclose(stdin);
92  #endif
93    return 0;
94}

Related

hdu 1171 Big Event in HDU (母函数,01背包)

·3 mins
**Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 26534 Accepted Submission(s): 9332 ** Problem Description Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe you don’t know that Computer College had ever been split into Computer College and Software College in 2002. The splitting is absolutely a big event in HDU! At the same time, it is a trouble thing too. All facilities must go halves. First, all facilities are assessed, and two facilities are thought to be same if they have the same value. It is assumed that there is N (0<N<1000) kinds of facilities (different value, different kinds).