【母函数】hdu1028 Ignatius and the Princess III
大意是给你1个整数n,问你能拆成多少种正整数组合。比如4有5种:
4 = 4;
4 = 3 + 1;
4 = 2 + 2;
4 = 2 + 1 + 1;
4 = 1 + 1 + 1 + 1;
然后就是母函数模板题……小于n的正整数每种都有无限多个可以取用。
(1+x+x^2+...)(1+x^2+x^4+...)...(1+x^n+...)
答案就是x^n的系数。
#include<cstdio>
#include<cstring>
using namespace std;
int n,a[123],b[123];
int main()
{
while(scanf("%d",&n)!=EOF)
{
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
a[0]=1;
for(int i=1;i<=n;++i)
{
for(int j=0;j<=n;++j)
for(int k=0;k*i+j<=n;++k)
b[k*i+j]+=a[j];
memcpy(a,b,sizeof(a));
memset(b,0,sizeof(b));
}
printf("%d\n",a[n]);
}
return 0;
}
【母函数】hdu1028 Ignatius and the Princess III的更多相关文章
- HDU1028 Ignatius and the Princess III 【母函数模板题】
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- hdu1028 Ignatius and the Princess III(递归、DP)
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- ACM学习历程—HDU1028 Ignatius and the Princess III(递推 || 母函数)
Description "Well, it seems the first problem is too easy. I will let you know how foolish you ...
- hdu1028 Ignatius and the Princess III
这是道典型的母函数的题目,可以看看我的母函数这一标签上的另一道例题,里面对母函数做了较为详细的总结.这题仅贴上代码: #include"iostream" using namesp ...
- HDU-1028 Ignatius and the Princess III(生成函数)
题意 给出$n$,问用$1$到$n$的数字问能构成$n$的方案数 思路 生成函数基础题,$x^{n}$的系数即答案. 代码 #include <bits/stdc++.h> #define ...
- hdu1028 Ignatius and the Princess III(生成函数整理占坑)upd 已咕
先咕着 ---------------2018 5 22---------------------- 题解 生成函数处理整数拆分 code #include<cstdio> #includ ...
- 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 ...
- Ignatius and the Princess III HDU - 1028 || 整数拆分,母函数
Ignatius and the Princess III HDU - 1028 整数划分问题 假的dp(复杂度不对) #include<cstdio> #include<cstri ...
随机推荐
- [spoj DISUBSTR]后缀数组统计不同子串个数
题目链接:https://vjudge.net/contest/70655#problem/C 后缀数组的又一神奇应用.不同子串的个数,实际上就是所有后缀的不同前缀的个数. 考虑所有的后缀按照rank ...
- idea 的http client的使用
1.打开idea的http client的工具步骤如下图所示: 然后在http client 的工具里写:请求头,请求参数,请求体即可.
- angular js的Inline Array Annotation的理解
inline Array annotation的形式是: someModule.controller('MyController', ['$scope', 'greeter', function($s ...
- bzoj 2566 calc 拉格朗日插值
calc Time Limit: 30 Sec Memory Limit: 512 MBSubmit: 377 Solved: 226[Submit][Status][Discuss] Descr ...
- bootstrap再次回顾认识到的东西
1,需要使用html5文档类型(Doctype),因此在使用bootstrap项目的开头包含下面的代码段. <!DOCTYPE html> <html> ....... < ...
- MDIO/MDC(SMI)接口-leonwang202
ChinaUnix博客 http://blog.chinaunix.net/uid-24148050-id-132863.html
- 【Foreign】红与蓝 [暴力]
红与蓝 Time Limit: 10 Sec Memory Limit: 256 MB Description Input Output Sample Input 2 2 0 1 -1 -1 2 0 ...
- 【BZOJ】ARC083 E - Bichrome Tree
[算法]树型DP [题意]给定含n个点的树的形态,和n个数字Xv,要求给每个点赋予黑色或白色和权值,满足对于每个点v,子树v中和v同色的点的权值和等于Xv.n<=10^5 [题解]首先每个点的权 ...
- 【洛谷 P4886】 快递员 (点分治)
这题因为一些小细节还是\(debug\)了很久...不过我第一次用脚本对拍,不亏. 先随便找一个点作为根,算出答案,即所有点对到这个点的距离和的最大值,并记录所有距离最大的点对.如果这个点在任意一个距 ...
- 最近研究xcodebuild批量打包的一些心得
http://blog.csdn.net/tlb203/article/details/8131707 转自Rainbird的个人博客 以前的时候只知道做安卓开发的兄弟挺辛苦的,不但开发的时候要适配一 ...