hdu 1028 & hdu 1398 —— 整数划分(生成函数)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1028
整数划分,每个数可以用无限次;
所以构造 f(x) = (1+x+x2+x3+...)(1+x2+x4+...)(1+x3+x6+...)...(1+xn)
乘起来后的 xn 的系数就是方案数;
用两个数组做即可,从第一个括号开始一个一个乘,f[i] 表示此时 xi 项的系数,后面每乘过来一个括号,相当于多了一种转移,所以加上。
代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int const xn=;
int n,f[xn],t[xn];
int main()
{
while(scanf("%d",&n)==)
{
for(int i=;i<=n;i++)f[i]=,t[i]=;
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
for(int k=;k<=n;k+=i)t[j+k]+=f[j];
for(int j=;j<=n;j++)f[j]=t[j],t[j]=;
}
printf("%d\n",f[n]);
}
return ;
}
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1398
同上。
代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int const xn=;
int n,f[xn],t[xn];
int main()
{
n=;
for(int i=;i<=n;i++)f[i]=,t[i]=;
for(int i=;i<=;i++)
{
int s=i*i;
for(int j=;j<=n;j++)
for(int k=;j+k<=n;k+=s)t[j+k]+=f[j];
for(int j=;j<=n;j++)f[j]=t[j],t[j]=;
}
while()
{
scanf("%d",&n); if(!n)return ;
printf("%d\n",f[n]);
}
}
hdu 1028 & hdu 1398 —— 整数划分(生成函数)的更多相关文章
- 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 1398 整数划分变形 (母函数)
有1,4,9,16,25.....2^17这么多面值的硬币,问任意给定一个不大于300的正整数面额,用这些硬币来组成此面额总共有多少种组合种数 比如10全14 + 6个 14+4+1+19+1 求(1 ...
- HDU 1028 HDU 1398 (母函数)
题意:输入一个n 给出其所有组合数 如: 4 = 4; 4 = 3 + 1; 4 = 2 + 2; 4 = 2 + 1 + 1; 4 = 1 + 1 + 1 + 1; 重复不算 母函数入门题 ...
- HDU 1028 HDU Ignatius and the Princess III
简单的钱币兑换问题,就是钱的种类多了一点,完全背包. #include<cstdio> #include<cstring> int main () { ]; memset(dp ...
- HDU 1028 Ignatius and the Princess III dp整数划分
http://acm.hdu.edu.cn/showproblem.php?pid=1028 dp[i][j]表示数值为i,然后最小拆分的那个数是j的时候的总和. 1 = 1 2 = 1 + 1 . ...
- HDU 1028 Ignatius and the Princess III 整数的划分问题(打表或者记忆化搜索)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1028 Ignatius and the Princess III Time Limit: 2000/1 ...
- HDU 1028 整数拆分 HDU 2082 找单词 母函数
生成函数(母函数) 母函数又称生成函数.定义是给出序列:a0,a1,a2,...ak,...an, 那么函数G(x)=a0+a1*x+a2*x2+....+ak*xk +...+an* xn 称为序 ...
- HDU 5230 ZCC loves hacking 大数字的整数划分
http://acm.hdu.edu.cn/showproblem.php?pid=5230 把题目简化后,就是求 1---n - 1这些数字中,将其进行整数划分,其中整数划分中不能有重复的数字,如果 ...
- Ignatius and the Princess III HDU - 1028 || 整数拆分,母函数
Ignatius and the Princess III HDU - 1028 整数划分问题 假的dp(复杂度不对) #include<cstdio> #include<cstri ...
随机推荐
- 转帖:HttpStatusCode状态说明C#版
Continue 等效于 HTTP 状态 100.Continue 指示客户端可能继续其请求. SwitchingProtocols 等效于 HTTP 状态 101.SwitchingProtocol ...
- 从TCP协议的原理来谈谈rst复位攻击
在谈RST攻击前,必须先了解TCP:如何通过三次握手建立TCP连接.四次握手如何把全双工的连接关闭掉.滑动窗体是怎么数据传输的.TCP的flag标志位里RST在哪些情况下出现.以下我会画一些尽量简化的 ...
- webpack 项目实战
步骤一: npm init 步骤二: npm install -D clean-webpack-plugin css-loader extract-text-webpack-plugin html-w ...
- Python中的列表、元祖、字典
一.列表 一组有序项目的集合.可变的数据类型[可进行增删改查] 列表是以方括号"[]"包围的数据集合,不同成员以","分隔. 列表中能够包括不论什么数据类型,也 ...
- Something about cache
http://www.tyut.edu.cn/kecheng1/2008/site04/courseware/chapter5/5.5.htm 5.5 高速缓冲存储器cache 随着CPU时钟速率的不 ...
- ok6410[001] Ubuntu 16.04[64bit]嵌入式交叉编译环境arm-linux-gcc搭建过程图解
开发PC:Ubuntu16.04.1 开发板:OK6410[飞凌公司出品] 目标:通过GPIO点亮LED ----------------------------------------------- ...
- unittest相关文档
文档链接: http://blog.csdn.net/wangst4321/article/details/8454118
- vim 参数文件配置
下面是我配置的遇到问题不能修改配置文件时的解决方案 1 /usr/share/vim/vimrc 2 这个是系统型的vimrc配置文件,为了保证vim的正常使用,一般并不会修改这个文件, 而是应该在你 ...
- switch中的case不加break执行情况
输出结果:230 分析,switch先匹配一个case满足$a,然后执行case里面的语句,直到遇到break,否则一直往下执行 <?php $a = ; switch($a){ : echo ...
- 目标检测之积分图---integral image 积分图2
前面在图像处理一栏中涉及到boxfilter 的时候,简单介绍过积分图,就是每个像素点是左边和上边的累加和,这样的话可以方便均值和方差,以及直方图统计的相关运算,这里再次结合网络资源重新单独对积分图做 ...