题目: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 —— 整数划分(生成函数)的更多相关文章

  1. 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+ ...

  2. hdu 1398 整数划分变形 (母函数)

    有1,4,9,16,25.....2^17这么多面值的硬币,问任意给定一个不大于300的正整数面额,用这些硬币来组成此面额总共有多少种组合种数 比如10全14 + 6个 14+4+1+19+1 求(1 ...

  3. HDU 1028 HDU 1398 (母函数)

    题意:输入一个n  给出其所有组合数 如: 4 = 4;  4 = 3 + 1;  4 = 2 + 2;  4 = 2 + 1 + 1;  4 = 1 + 1 + 1 + 1; 重复不算 母函数入门题 ...

  4. HDU 1028 HDU Ignatius and the Princess III

    简单的钱币兑换问题,就是钱的种类多了一点,完全背包. #include<cstdio> #include<cstring> int main () { ]; memset(dp ...

  5. 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 . ...

  6. 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 ...

  7. HDU 1028 整数拆分 HDU 2082 找单词 母函数

    生成函数(母函数) 母函数又称生成函数.定义是给出序列:a0,a1,a2,...ak,...an, 那么函数G(x)=a0+a1*x+a2*x2+....+ak*xk +...+an* xn  称为序 ...

  8. HDU 5230 ZCC loves hacking 大数字的整数划分

    http://acm.hdu.edu.cn/showproblem.php?pid=5230 把题目简化后,就是求 1---n - 1这些数字中,将其进行整数划分,其中整数划分中不能有重复的数字,如果 ...

  9. Ignatius and the Princess III HDU - 1028 || 整数拆分,母函数

    Ignatius and the Princess III HDU - 1028 整数划分问题 假的dp(复杂度不对) #include<cstdio> #include<cstri ...

随机推荐

  1. git 怎样删除远程仓库的最近一次错误提交?

    假设你有3个commit如下: commit 3 commit 2 commit 1 其中最后一次提交commit 3是错误的,那么可以执行: git reset --hard HEAD~1 你会发现 ...

  2. 如何防范SQL注入式攻击

    一.什么是SQL注入式攻击? 所谓SQL注入式攻击,就是攻击者把SQL命令插入到Web表单的输入域或页面请求的查询字符串,欺骗服务器执行恶意的SQL命令.在某些表单中,用户输入的内容直接用来构造(或者 ...

  3. Unix系统介绍

    一.基础知识 操作系统 用户与计算机硬件之间的界面,是控制.管理计算机内各种硬件与软件资源.它是一个多用户.多任务.分时的操作系统. 对于分时系统:假如a进程需要16个时间片,现在根据优先级只分配了1 ...

  4. Python--数据类型整理

      数据类型整理-------------------------------------------------------------------------------------------- ...

  5. 二进制安装Mysql 5.6(免编译)

    安装系统基础软包 yum install -y make bc perl gcc openssl openssl-devel ncurses ncurses-devel 安装方式:二进制免编译安装 查 ...

  6. moving from a host-centric infrastructure to a container-centric infrastructure

    https://kubernetes.io/docs/concepts/overview/what-is-kubernetes/ Why do I need Kubernetes and what c ...

  7. 解决Windows x64bit环境下无法使用PLSQL Developer连接到Oracle DB中的问题

    本文是原创文章,转载请注明出处: http://blog.csdn.net/msdnchina/article/details/46416455 解决Windows x64bit环境下无法使用PLSQ ...

  8. rtmp搭建直播系统

    开发环境 Ubuntu 14.04 server nginx-1.8.1 nginx-rtmp-module nginx的服务器的搭建 安装nginx的依赖库 sudo apt-get update ...

  9. Java生成UUID不重复的id值

    在Java中创建UUID在网上查资料才知道在Java中,变成了UUID.创建方式也出奇简单System.out.println( java.util.UUID.randomUUID());

  10. zkdash部署

    1.拉取代码 #git clone https://github.com/ireaderlab/zkdash.git 2.安装依赖包 #cd zkdash #yum install -y python ...