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 ...
随机推荐
- java实验8-Java输入输出流
1 读写文件 [实验目的] (1)掌握文本文件的读写方法. (2)掌握随机文件的读写方法. (3)掌握InputStream.OutputStream抽象类的基本使用. (4)掌握FileInputS ...
- Windows 编程1
杀死一个进程 使用命令 system( taskkill /f /im QQ.exe); 即可. 打开一个进程 使用命令 system("应用程序的位置"); 头文件: ...
- Plug and Play
http://baike.baidu.com/view/33701.htm 即插即用 编辑 PNP是Plug-and-Play(即插即用)的缩写.它的作用是自动配置(低层)计算机中的板卡和其他设备 ...
- android中的常见对话框
在android中对话框是一种常见的操作,常见的对话框有下面几种: 以下是xml布局文件: <LinearLayout xmlns:android="http://schemas.an ...
- MSQL Webpage
Mars Nov 19, 2014
- OpenStack部署到Hadoop的四种方案
随着企业開始同一时候利用云计算和大数据技术.如今应当考虑怎样将这些工具结合使用.在这样的情况下,企业将实现最佳的分析处理能力.同一时候利用私有云的高速弹性 (rapid elasticity) 和单一 ...
- win10获取注册表权限
1.cmd中输入regedit打开注册表 2.在需要的注册表项中右键选择“权限”
- J++ C#
J++几乎有与Java相同的编程语言和虚拟机.
- Windows窗口程序从创建到关闭产生的消息
Windows是消息驱动的,理解消息机制及消息循环是特别重要.知道在什么情况下产生什么消息会让我们对程序有更好的控制.Windows给应用程序发消息,有些会加入应用程序的消息队列,也是就是队列消息.有 ...
- CSS3学习笔记(4)—上下滑动展开的按钮
最近写了一个动画,下面来看看我以前写的一个上下滑动展开的按钮效果: 这类的效果经常会在一些网站页面下载按钮处看到,当你鼠标悬浮在下载按钮时,会提醒你是否已注册,或者点击登录什么的小提示~~~~~ 一. ...