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

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

/* ***********************************************
Author :111qqz
Created Time :2016年02月25日 星期四 22时26分16秒
File Name :code/hdu.1085.cpp
************************************************ */
 1#include <cstdio>
 2#include <cstring>
 3#include <iostream>
 4#include <algorithm>
 5#include <vector>
 6#include <queue>
 7#include <set>
 8#include <map>
 9#include <string>
10#include <cmath>
11#include <cstdlib>
12#include <ctime>
13#define fst first
14#define sec second
15#define lson l,m,rt<<1
16#define rson m+1,r,rt<<1|1
17#define ms(a,x) memset(a,x,sizeof(a))
18typedef long long LL;
19#define pi pair < int ,int >
20#define MP make_pair
 1using namespace std;
 2const double eps = 1E-8;
 3const int dx4[4]={1,0,0,-1};
 4const int dy4[4]={0,-1,1,0};
 5const int inf = 0x3f3f3f3f;
 6const int N=9E3+7;
 7int num_1,num_2,num_5;
 8int a[N],tmp[N];
 9int main()
10{
11    #ifndef  ONLINE_JUDGE 
12    freopen("code/in.txt","r",stdin);
13  #endif
 1    while (~scanf("%d%d%d",&num_1,&num_2,&num_5))
 2    {
 3        if (num_1==0&&num_2==0&&num_5==0) break; 
 4        ms(a,0);
 5        int total = num_1+2*num_2+5*num_5;
 6        for ( int i = 0 ; i <= num_1; i++)
 7        {
 8        a[i] = 1;
 9        tmp[i] = 0;
10        }
1        for ( int j = 0 ; j <= num_1 ; j++)
2        {
3        for ( int k =  0; k <=num_2 ; k++)
4        {
5            tmp[j+2*k] += a[j];
6        }
7        }
1        for ( int j = 0 ; j <= num_1 +2*num_2 ; j++)
2        {
3        a[j] = tmp[j];
4        tmp[j] = 0 ;
5        }
 1        for ( int j = 0 ; j <= num_1+2*num_2 ; j++)
 2        {
 3        for ( int k =  0;  k <= num_5 ; k++)
 4        {
 5            tmp[j+5*k]+=a[j];
 6        }
 7        }
 8        for ( int j = 0 ; j <= total ; j++)
 9        {
10        a[j] = tmp[j];
11        tmp[j] =  0 ;
12        }
1        for ( int i = 0 ; i <= total +1 ; i ++)
2        {
3        if (a[i]==0)
4        {
5            printf("%d\n",i);
6            break;
7        }
8        }
9    }
1  #ifndef ONLINE_JUDGE  
2  fclose(stdin);
3  #endif
4    return 0;
5}