Ignatius and the Princess III HDU - 1028 -生成函数or完全背包计数
step 1:初始化第一个多项式 也就是 由 1的各种方案 组 成 的多项式 初始化系数为 1。临时区 temp初始化 为 0
step 2:遍历后续的n - 1 个 多项式 ,第二重 for j 代 表 的 存 储 结 果 的 多 项 式的次数,k 代表 当前 第 i 的 多项式的次数
通过计算发现两个多项式相乘 其中一个 系数为1和 0 组成,运算时可以初始化系数数组为0 ,然后 由另一个的系数 与之相加即可得到
G(x)=(1+x+x2+x3+x4+.....)(1+x2+x4+x6+x8+......)(1+x3+x6+x9+....)........(1+xn)
#include<bits/stdc++.h>
using namespace std;
#define maxn 234
int ans[maxn],tp[maxn],n;
int main()
{
while(~scanf("%d",&n))
{
for(int i=0; i<=n; i++)
ans[i]=1,tp[i]=0;
for(int i=2; i<=n; i++)
{
for(int j=0; j<=n; j++)
for(int k=0; k+j<=n; k+=i)
tp[j+k]+=ans[j];
for(int j=0; j<=n; j++)
ans[j]=tp[j],tp[j]=0;
}
printf("%d\n",ans[n]);
}
return 0;
}
Ignatius and the Princess III HDU - 1028 -生成函数or完全背包计数的更多相关文章
- Ignatius and the Princess III HDU - 1028 || 整数拆分,母函数
Ignatius and the Princess III HDU - 1028 整数划分问题 假的dp(复杂度不对) #include<cstdio> #include<cstri ...
- Ignatius and the Princess III HDU - 1028
题目传送门:https://vjudge.net/problem/HDU-1028 思路:整数拆分构造母函数的模板题 1 //#include<bits/stdc++.h> 2 #incl ...
- hdu acm 1028 数字拆分Ignatius and the Princess III
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- hdu 1028 Ignatius and the Princess III 简单dp
题目链接:hdu 1028 Ignatius and the Princess III 题意:对于给定的n,问有多少种组成方式 思路:dp[i][j],i表示要求的数,j表示组成i的最大值,最后答案是 ...
- 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 Ignatius and the Princess III(DP)
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- HDU 1028 整数拆分问题 Ignatius and the Princess III
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- HDU 1028 Ignatius and the Princess III (母函数或者dp,找规律,)
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- hdu 1028 Ignatius and the Princess III 母函数
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
随机推荐
- LeetCode(112):路径总和
Easy! 题目描述: 给定一个二叉树和一个目标和,判断该树中是否存在根节点到叶子节点的路径,这条路径上所有节点值相加等于目标和. 说明: 叶子节点是指没有子节点的节点. 示例: 给定如下二叉树,以及 ...
- 【ftp】主动模式和被动模式
来自:http://blog.csdn.net/liuhelong12/article/details/50218311 原博主不让转载全文,不过下面这部分是原博主转载别人的,所以我拿过来应该没问题吧 ...
- mysql 各种关系代数的使用
连接(JOIN) 选择运算表示为: R⋈S ,其中R和S为不同的两个关系 连接运算是选取两个指定关系中的属性满足给定条件的元祖连接在一起来组成一个新的关系 数学形式: JOIN 关系名1 AND 关系 ...
- C#概念总结(二)
1.C#的方法:<access Specifier> <Return Type>< Method Name>(Parmeter list){ method ...
- Eclipse中部署Android开发环境插件安装问题方案
1.添加第一个插件ADT之后出现eclipse原有的SDK管理问题.需要重新安装SDK 2.一种方式按照系统提示直接联网自动搜索安装,另一种就是下载好之后import. 1.用接口声明的变量称为接口变 ...
- JAVA菜鸟入门HelloWorld
一:HelloWorld进入菜鸟心中 1.最原始的一切从HelloWorld开始 首先本机安装JDK,配置好path环境变量 用文本编辑器editplus或notepad++创建一个HelloWorl ...
- animate方法使用总结
<!DOCTYPE html><html lang="en" class="loading"><head> <meta ...
- 3月9日(用 DBHelper 工具连接 mysql 数据库 实现登录验证)
一. 用DBHelper 与mysql 连接 实现最简单的登录验证. (1)新建 web project ----->选择src导入 DBHelper 工具包-------->选择web ...
- Python知乎热门话题数据的爬取实战
import requestsfrom pyquery import PyQuery as pq url = 'https://www.zhihu.com/explore'headers = { 'u ...
- 用servlet打内容到网页上
关键代码 response.setContentType("text/html;charset=UTF-8"); PrintWriter out=response.getWrite ...