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 ...
随机推荐
- nginx官方模块之http_sub_module
作用 http内容替换 语法 示例 html代码与结果如下:
- LeetCode(88):合并两个有序数组
Easy! 题目描述: 给定两个有序整数数组 nums1 和 nums2,将 nums2 合并到 nums1 中,使得 num1 成为一个有序数组. 说明: 初始化 nums1 和 nums2 的元素 ...
- HTML&javaSkcript&CSS&jQuery&ajax(八)
一. <!DOCTYPE html><html><head><meta charset="utf-8"><tiitle> ...
- Python判断字符串是否xx开始或结尾
判断是否xx开始 使用startswith 示例代码: String = "12345 上山打老虎" if str(String).startswith('1'): #判断Stri ...
- Allegro PCB Design GXL (legacy) 元器件的坐标文件
Allegro PCB Design GXL (legacy) version 16.6-2015 一.菜单:Tools > Reports... 二.在“Available Reports ( ...
- js FileReader 笔记
以上传图片为例 通过input type='file' 上传完成图片后,获取图片 $('#input').files[0] var reader = new FileReader(); read ...
- 饮冰三年-人工智能-linux-02 初始Linux
参考博客:https://www.cnblogs.com/linhaifeng/articles/6045600.html 1:初始Linux命令 右击,开启终端,或者ctrl+alt[F1-F6]的 ...
- hive内group by取第一条数据,Hive中row_number的使用
1.hive的分组和组内排序---语法 语法: row_number() over (partition by 字段a order by 计算项b desc ) rank rank是排序的别名 par ...
- linux服务器上简单命令
linux命令 1.ifconfig 查看 设置ip: 2.连接另一台linux 命令 ssh; 3.查看尾部 新追加内容 tail -f; 4.ln -s 原命令 新命令路径: 5.创建一个空文件 ...
- [转] 跨域资源共享 CORS 详解
CORS是一个W3C标准,全称是"跨域资源共享"(Cross-origin resource sharing). 它允许浏览器向跨源服务器,发出XMLHttpRequest请求,从 ...