hdu 1085
额 母函数
#include <cstdio>
#include <cstring> int a[3],b[3]= {1,2,5};
int c1[10001],c2[10001],sum; int main()
{
while(scanf("%d%d%d",&a[0],&a[1],&a[2]) && a[0]+a[1]+a[2])
{
sum=a[0] + 2*a[1] + 5*a[2];
memset(c1, 0, sizeof(c1));
memset(c2, 0, sizeof(c2));
c1[0] = 1;
for(int i = 0; i < 3; i++)
{
for(int j = 0; j <= sum; j++)
if(c1[j])
for(int k = 0; j+k <= sum && k <= b[i]*a[i]; k += b[i])
c2[k+j] += c1[j];
for(int j = 0; j <= sum; j++)
{
c1[j] = c2[j];
c2[j] = 0;
}
}
int i;
for(i = 0; i <= sum; i++)
if(!c1[i])
break;
printf("%d\n",i);
}
return 0;
}
因为输出错 wa好几遍
#include <cstdio>
#include <cstring> int a[3],b[3] = {1, 2, 5};
int c[10001], sum;
int c2[10001]; int main()
{
while(scanf("%d%d%d",&a[0],&a[1],&a[2]) && a[0]+a[1]+a[2])
{
sum = a[0] + 2*a[1] + 5*a[2];
memset(c, 0, sizeof(c));
memset(c2, 0, sizeof(c2));
c[0] = 1;
int v = 0;
for(int i = 0; i < 3; i++)
{
for(int j = 0; j <= v; j++)
if(c[j])
for(int k = 1; k <= a[i]; k++)
c2[k*b[i]+j] = 1;
v += a[i]*b[i];
for(int j = 0; j <= v; j++)
{
if(!c[j])
c[j] = c2[j];
c2[j] = 0;
}
}
int i;
for(i = 0; i <= sum; i++)
if(!c[i])
break;
printf("%d\n",i);
}
return 0;
}
hdu 1085的更多相关文章
- 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, ...
- hdu 1028 && hdu 1398 && hdu 1085 && hdu 1171 ——生成函数
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1028 就是可以用任意个1.2.3....,所以式子写出来就是这样:(1+x+x^2+...)(1+x^2+ ...
- HDU 1085 Holding Bin-Laden Captive! 活捉本拉登(普通型母函数)
题意: 有面值分别为1.2.5的硬币,分别有num_1.num_2.num_5个,问不能组成的最小面值是多少?(0<=每种硬币个数<=1000,组成的面值>0) 思路: 母函数解决. ...
- HDU 1085 Holding Bin-Laden Captive --生成函数第一题
生成函数题. 题意:有币值1,2,5的硬币若干,问你最小的不能组成的币值为多少. 解法:写出生成函数: 然后求每项的系数即可. 因为三种硬币最多1000枚,1*1000+2*1000+5*1000=8 ...
- HDOJ/HDU 1085 Holding Bin-Laden Captive!(非母函数求解)
Problem Description We all know that Bin-Laden is a notorious terrorist, and he has disappeared for ...
- HDU 1085 Holding Bin-Laden Captive! (母函数)
Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- hdu 1085 Holding Bin-Laden Captive!
Problem Description We all know that Bin-Laden is a notorious terrorist, and he has disappeared for ...
- hdu 1085 Holding Bin-Laden Captive! (母函数)
//给你面值为1,2,5的三种硬币固定的数目,求不能凑出的最小钱数 //G(x)=(1+x+...+x^num1)(1+x^2+...+x^2num2)(1+x^5+,,,+x^5num3), //展 ...
- 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 Input1 ...
随机推荐
- IT技术开发人员35岁之前应该做的十件事
第一,学会本行业所需要的一切知识并有所发展.已故零件大王布鲁丹在他35岁时,已经成为零件行业的领袖,并且组建了年收入达千万美元的海湾与西部工业公司.每个人在年轻时都可能有过彻夜不眠.刻苦攻读,这在20 ...
- CSS之照片翻转
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="C ...
- Unity3D项目实战笔记(5):延时功能的几种实现
我所做过的系统,分单机版系统(2005年).CS系统(2010年).实时系统(2015年),各个系统均有“延时”功能:定时调度的: 本博客说的是实时系统中的延时功能(基于Unity3D游戏引擎). 在 ...
- OC3_dealloc
// // Dog.h // OC3_dealloc // // Created by zhangxueming on 15/6/18. // Copyright (c) 2015年 zhangxue ...
- 高性能CSS(三)
CSS选择器对性能的影响源于浏览器匹配选择器和文档元素时所消耗的时间,所以优化选择器的原则是应尽量避免需要消耗更多匹配时间的选择器.而在这之前我们需要了解CSS选择器匹配的机制,如例子的子选择器规则: ...
- Z-Stack内部API 小结
Z-Stack是TI推出的全功能ZigBee协议栈,通过了ZigBee联盟的兼容性平台测试,包含如下几个组件. 1. HAL,硬件抽象层 2. OSAL,操作系统抽象层 3. ZigBee Stack ...
- JS 框架
<html xmlns=”http://www.w3.org/1999/xhtml”> <head> <title>Untitled Page</title& ...
- [转]Nuget挂了的解决方法
今天用Nuget下一个程序包时,发现Nuget挂了:未能解析此远程名称:'nuget.org'.第一反应就是方校长抖威风了,挂个代理上 http://nuget.org 试了下,果然好好的. 用命令n ...
- mysql中的count(primary_key)、count(1)、count(*)的区别
表结构如下: mysql> show create table user\G; *************************** 1. row ********************** ...
- window.onbeforeunload 如果取消, 那么javascript变量会保存
function confirmQuit1() { if (ischanged) return 'it is changed !! '; else return 'no change .. '; } ...