HDU ACM 1085 Holding Bin-Laden Captive! 母函数?

分析:这题可以用母函数做,但可以找到简单的规律。

1、若1的个数为0,则输出1;

2、若1的个数不为0,则从1到n1+2*n2的数都能拼成;接着,只需考虑5的个数,若n1+2*n2能到4以上,则在所有5的组合中,中间4个间隔可以由n1+2*n2

填充,这时总和为S,则1到S之间的数都可以组成;

3、若n1+2*n2不能达到4,则开始达到5之前就断开了不能到5,就不用再去组合5的个数了。

#include<iostream>
using namespace std;

int main()
{
	int a,b,c;

	while(cin>>a>>b>>c && a+b+c)
	{
		if(!a)
			cout<<1<<endl;
		else if(a+b*2<4)
			cout<<a+b*2+1<<endl;
		else
			cout<<a+2*b+c*5+1<<endl;
	}
    return 0;
}
时间: 2024-10-20 02:55:20

HDU ACM 1085 Holding Bin-Laden Captive! 母函数?的相关文章

杭电 HDU ACM 1085 Holding Bin-Laden Captive!

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

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 acm 2082 找单词

找单词 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3722    Accepted Submission(s): 2663 Problem Description 假设有x1个字母A, x2个字母B,..... x26个字母Z,同时假设字母A的价值为1,字母B的价值为2,..... 字母Z的价值为26.那么,对于给定的字母,可以找到

hdu acm 1028 数字拆分Ignatius and the Princess III

Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 11810    Accepted Submission(s): 8362 Problem Description "Well, it seems the first problem is too easy. I will let

HDU ACM 1103 Flo&#39;s Restaurant

分析:借助STL的min_element实现.每次更新最先被占用的桌子,具体见注释. #include<iostream> #include<algorithm> using namespace std; int main() { int A,B,C; char s[10]; int a[102],b[102],c[102]; int curtime,count,ans; int *p; //桌子最先空闲时间 while(cin>>A>>B>>C

hdu acm 1425 sort(哈希表思想)

sort Time Limit: 6000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 25803    Accepted Submission(s): 7764 Problem Description 给你n个整数,请按从大到小的顺序输出其中前m大的数. Input 每组测试数据有两行,第一行有两个数n,m(0<n,m<1000000),第二行包含n个各不相同,且

HDU ACM 1005 Number Sequence

Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 119732    Accepted Submission(s): 29072 Problem Description A number sequence is defined as follows:f(1) = 1, f(2) = 1, f(n) = (A

hdu acm 1166 敌兵布阵 (线段树)

敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 37903    Accepted Submission(s): 15985 Problem Description C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务

HDU ACM 1025 Constructing Roads In JGShining&amp;#39;s Kingdom-&amp;gt;二分求解LIS+O(NlogN)

#include<iostream> using namespace std; //BFS+优先队列(打印路径) #define N 500005 int c[N]; int dp[N]; //dp[i]保存的是长度为i的最长不降子序列的最小尾元素 int BS(int n,int x) //二分查找下标,当x比全部元素小时下标为1,比全部元素大时下标为n+1. { int low,high,mid; low=1,high=n; while(low<=high) { mid=(low+h