hdu 1085 有num1个 1 ,num2个 2 ,num3个 5 (母函数)

有num1个 1 ,num2个 2 ,num3个 5
问它们不能组成的最小正整数是谁

样例的母函数 (1+X)(1+X2)(1+X5+X10+X15)
展开后 X4的系数为0

Sample Input
1 1 3
0 0 0

Sample Output
4

 1 # include <iostream>
 2 # include <cstdio>
 3 # include <cstring>
 4 # include <algorithm>
 5 # include <string>
 6 # include <cmath>
 7 # include <queue>
 8 # include <list>
 9 # define LL long long
10 using namespace std ;
11
12 int c1[10010], c2[10010] ;
13 int num[5] ;
14 int main()
15 {
16
17     while(scanf("%d %d %d", &num[1], &num[2], &num[3])!= EOF )
18     {
19         if (num[1] == 0 && num[2] == 0 && num[3] == 0)
20             break ;
21         int Max = num[1]*1+num[2]*2+num[3]*5;
22
23         for(int i=0; i<=Max; ++i)
24         {
25             c1[i] = 0;
26             c2[i] = 0;
27         }
28         for(int i=0; i<=num[1]; ++i)
29             c1[i] = 1;
30         for(int i=0; i<=num[1]; ++i)
31             for(int j=0; j<=num[2]*2; j+=2)
32                 c2[j+i] += c1[i];
33         for(int i=0; i<=num[2]*2+num[1]*1; ++i)
34         {
35             c1[i] = c2[i];
36             c2[i] = 0;
37         }
38
39         for(int i=0; i<=num[1]*1+num[2]*2; ++i)
40             for(int j=0; j<=num[3]*5; j+=5)
41                 c2[j+i] += c1[i];
42         for(int i=0; i<=num[2]*2+num[1]*1+num[3]*5; ++i)
43         {
44             c1[i] = c2[i];
45             c2[i] = 0;
46         }
47         int i;
48
49         for(i=0; i<=Max; ++i)
50             if(c1[i] == 0)
51             {
52                 printf("%d\n", i);
53                 break;
54             }
55         if(i == Max+1)
56             printf("%d\n", i);
57     }
58     return 0;
59 }

时间: 2024-10-02 20:17:18

hdu 1085 有num1个 1 ,num2个 2 ,num3个 5 (母函数)的相关文章

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

http://acm.hdu.edu.cn/showproblem.php?pid=1085 题意:1元,2元,5元的硬币分别有num[1],num[2],num[3]个.问用这些硬币不能组合成的最小钱数. 继续母函数. 有两个注意的地方: 对c2[]初始化的同时也要对c1[]初始化. 最后枚举到sum+1,因为存在[1,sum]都可以凑成的可能,这时输出sum+1. #include <stdio.h> #include <iostream> #include <map&g

HDU 1085

想来想去都有bug 最后简单粗暴的一个一个来处理了 #include<stdio.h> #include<string.h> #include<math.h> #include<iostream> #include<algorithm> #include<queue> #include<stack> #define mem(a,b) memset(a,b,sizeof(a)) #define ll __int64 #def

居然因为交换错了好几把。。。。,还有坑点是num1可以大于num2

完数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 22289    Accepted Submission(s): 8150 Problem Description 完数的定义:如果一个大于1的正整数的所有因子之和等于它的本身,则称这个数是完数,比如6,28都是完数:6=1+2+3:28=1+2+4+7+14. 本题的任务是判断两个正

HDU 1085 Holding Bin-Laden Captive!(DP)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1085 解题报告:有1,2,5三种面值的硬币,这三种硬币的数量分别是num_1,num_2,num_5,问你不能凑的钱的最小值是多少. DP,开一个这样的数组dp[i][3],然后dp[i][0]表示凑成 i 元钱需要dp[i][0]张1块的,需要dp[i][1]张两块的,dp[i][2]张5块的,然后依次往后递推,得到 i 的途径一共有三种,第一种是i-1加一张一块的,第二种是i-2加上1张两块的,

HDU 1085 Holding Bin-Laden Captive!

Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) 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

HDU 1085 Holding Bin-Laden Captive! 活捉本拉登(AC代码)普通型母函数

题意:有面值分别为1.2.5的硬币,分别有num_1.num_2.num_5个,问不能组成的最小面值是多少?(0<=每种硬币个数<=1000,组成的面值>0) 思路:母函数解决.只有3个括号要作乘法,分别代表面值1.2.5所能组成的情况.需要两个数组,所能组成的最大值为num_1+2*num_2+5*num_5.如果在这个范围内都能组成,那么最小不能组成的面值为num_1+2*num_2+5*num_5+1.若没有1分钱的硬币,那么不能组成的肯定是1了. 数组的用法:ans[]保存第一个

hdu 1085(普通母函数)

Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 21240    Accepted Submission(s): 9420 Problem Description We all know that Bin-Laden is a notorious terrorist, and he h

HDOJ/HDU 1085 Holding Bin-Laden Captive!(非母函数求解)

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 hi

(母函数) hdu 1085

Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 16562    Accepted Submission(s): 7443 Problem Description We all know that Bin-Laden is a notorious terrorist, and he h