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 ...
随机推荐
- 标准库string类型简述
若想使用标准库的string类需要使用如下声明: #include <string> Using std::string: Using std::wstring: 那么就可以使用这两个类了 ...
- PHP学习笔记 - 进阶篇(9)
PHP学习笔记 - 进阶篇(9) 图形图像操作 GD库简介 GD指的是Graphic Device,PHP的GD库是用来处理图形的扩展库,通过GD库提供的一系列API,可以对图像进行处理或者直接生成新 ...
- C#学习笔记之线程 - 高级主题:非阻塞同步
非阻塞同步 - Nonblock Synchronization 前面提到,即使在简单的赋值和增加一个字段的情况下也需要处理同步.尽管,使用锁可以完成这个功能,但是锁必定会阻塞线程,需要线程切换,在高 ...
- c语言与c++基础知识
1.后缀名: C++/C程序的头文件以.h为后缀,C程序的源文件以.c为后缀,C++程序的源文件通常以.cpp为后缀(有些书中介绍有一些系统以.cc或.cxx为后缀的源文件).在Linux系统下的gc ...
- linux gcc 和 g++ 编译
gcc编译 gcc -o test.out test.c g++ 编译 g++ -o test.out test.cpp
- js-shortid:优雅简洁地实现短ID
短ID在实际运用中很广泛, 其中比较典型的运用就是短地址. 市面上肯定有不少开源的生成短ID库, 基于node.js的估计也不少. 鉴于本人已然是node.js的脑残粉(本职java开发), 很多业余 ...
- [译]Java Thread Sleep示例
Java Thread Sleep示例 java.lang.Thread sleep(long millis)方法被用来暂停当前线程的执行,暂停时间由方法参数指定,单位为毫秒.注意参数不能为负数,否则 ...
- [Oracle]Oracle学习小结(1)
1.查看Oracle数据库中的所有用户: (1)使用具有DBA权限的账户登录数据库: (2)执行select username from dba_users. SQL> conn sys 输入口 ...
- Kakfa揭秘 Day6 Consumer源码解密
Kakfa揭秘 Day6 Consumer源码解密 今天主要分析下Consumer是怎么来工作的,今天主要是例子出发,对整个过程进行刨析. 简单例子 Example中Consumer.java是一个简 ...
- 字符设备驱动中cdev与inode、file_operations的关系
一.cdev与inode 二.cdev与file_operations