HDU 1085 Holding Bin-Laden Captive --生成函数第一题
生成函数题。
题意:有币值1,2,5的硬币若干,问你最小的不能组成的币值为多少。
解法:写出生成函数:

然后求每项的系数即可。
因为三种硬币最多1000枚,1*1000+2*1000+5*1000=8000,那么多项式乘积的最高次数为8000
用c保存累计相乘各项的系数,tc保存c和当前项相乘的系数
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
#define N 8007 int c[N],tc[N]; int main()
{
int num[],cnt[] = {,,};
int i,j,k;
while(scanf("%d%d%d",&num[],&num[],&num[])!=EOF)
{
if(num[] == && num[] == && num[] == )
break;
int maxi = num[] + *num[] + *num[]; for(i=;i<;i++)
c[i] = ,tc[i] = ; for(i=;i<=cnt[]*num[];i+=cnt[]) //第一个多项式的系数
c[i] = ; for(i=;i<;i++) //第几个多项式
{
for(j=;j<=maxi;j++) //累计的x^j的系数
{
for(k=;k+j<=maxi && k<=cnt[i]*num[i];k+=cnt[i]) //当前x^k的系数
tc[k+j] += c[j];
}
for(j=;j<=maxi;j++) //将结果保存到累计结果数组c中,重置tc
{
c[j] = tc[j];
tc[j] = ;
}
}
for(i=;i<=maxi;i++)
if(c[i] == )
break;
cout<<i<<endl;
}
return ;
}
HDU 1085 Holding Bin-Laden Captive --生成函数第一题的更多相关文章
- 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 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!(母函数,或者找规律)
Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- HDU 1085 Holding Bin-Laden Captive! 活捉本拉登(普通型母函数)
题意: 有面值分别为1.2.5的硬币,分别有num_1.num_2.num_5个,问不能组成的最小面值是多少?(0<=每种硬币个数<=1000,组成的面值>0) 思路: 母函数解决. ...
- 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!
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 5029 Relief grain --树链剖分第一题
题意:给一棵树,每次给两个节点间的所有节点发放第k种东西,问最后每个节点拿到的最多的东西是哪种. 解法:解决树的路径上的修改查询问题一般用到的是树链剖分+线段树,以前不会写,后来学了一下树链剖分,感觉 ...
- HDU 1312 Red and Black 第一题搜索!
Red and Black Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
随机推荐
- .NET Core常用配置文件示例
.NET Core相关地址: 1.官网:https://www.microsoft.com/net 2..NET Core:http://dotnet.github.io/3.Getting Star ...
- virtualenv and virtualenvwrapper on Ubuntu 14.04
In this post I’ll go over my attempt to setup virtual environments for Python development. Most Pyth ...
- 养只爬虫当宠物(Node.js爬虫爬取58同城租房信息)
先上一个源代码吧. https://github.com/answershuto/Rental 欢迎指导交流. 效果图 搭建Node.js环境及启动服务 安装node以及npm,用express模块启 ...
- ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded
The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramewor ...
- ng-click
使用ng-clcik代码是发现其内的a标签失效: 于是测试下,发现绑定在document上的click事件在点击ng-click绑定的元素上也会失效: <div ng-click="c ...
- JavaScript hasOwnProperty() 函数详解
hasOwnProperty()函数用于指示一个对象自身(不包括原型链)是否具有指定名称的属性.如果有,返回true,否则返回false. 该方法属于Object对象,由于所有的对象都"继承 ...
- Log4net中的调错
在使用log4net时,感觉最麻烦的就是配置文件了,为了使用方便,我不得不先准备好一个完整的配置文件方案,测试了输出到文本.控制台.windows事件.SQL Server数据库都没有问题,但输出到o ...
- 使用tinypng优化Android的资源图片
tinypng 是一个支持压缩png和jpg图片格式的网站,通过其独特的算法(通过一种叫“量化”的技术,把原本png文件的24位真彩色压缩为8位的索引演示,是一 种矢量压缩方法,把颜色值用数值123等 ...
- Hibernate的各种关联关系
1.有多中映射 方法 //用XML配置时 <mapping resource="com/liugch/bean/Student.hbm.xml" /> //用注解配置时 ...
- 使用SharedPreferences进行简单的储存
博客地址 http://www.cnblogs.com/mmyblogs/p/6082512.html(转载请保留) SharedPreferences定义 1.是一种轻型的数据存储的方式 2.本质是 ...