HDU1028 Ignatius and the Princess III【母函数】【完全背包】
来源:互联网 发布:手机可以做淘宝客服吗 编辑:程序博客网 时间:2024/05/22 03:20
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1028
题目大意:
给定正整数N,定义N = a[1] + a[2] + a[3] + … + a[m],a[i] > 0,1 <= m <= N。
对于给定的正整数N,问:能够找出多少种这样的等式?
思路:
对于N = 4,
4 = 4;
4 = 3 + 1;
4 = 2 + 2;
4 = 2 + 1 + 1;
4 = 1 + 1 + 1 + 1。
共有5种。N=4时,结果就是5。其实就是整数分解问题,可写出母函数
g(x) = (1+x+x^2+x^3+…)*(1+x^2+x^4+…)*(1+x^3+…)*(1+x^4+…)
直接套用母函数模板http://blog.csdn.net/lianai911/article/details/45567595求
出解即可。
其实,用完全背包也可以做,附上代码。
AC代码:
#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>using namespace std;int c1[130],c2[130];int main(){ int N; while(cin >> N) { for(int i = 0; i <= N; ++i) { c1[i] = 1; c2[i] = 0; } for(int i = 2; i <= N; ++i) { for(int j = 0; j <= N; ++j) for(int k = 0; j+k <= N; k += i) c2[j+k] += c1[j]; for(int j = 0; j <= N; ++j) { c1[j] = c2[j]; c2[j] = 0; } } cout << c1[N] << endl; } return 0;}
#include<stdio.h>#include<string.h>int dp[200];int main(){ dp[0] = 1; for(int i = 1; i <= 120; i++) { for(int j = i; j <= 120; j++) { dp[j] += dp[j-i]; } } int n; while(~scanf("%d",&n)) { printf("%d\n",dp[n]); } return 0;}
0 0
- HDU1028 Ignatius and the Princess III【母函数】【完全背包】
- 【完全背包/母函数/递推】HDU1028-Ignatius and the Princess III
- hdu1028 Ignatius and the Princess III (完全背包)
- HDU1028 Ignatius and the Princess III,母函数
- Ignatius and the Princess III(hdu1028母函数)
- Hdu1028 Ignatius and the Princess III 母函数
- hdu1028-Ignatius and the Princess III (母函数模板)
- HDU1028 Ignatius and the Princess III 【母函数模板题】
- HDU1028 Ignatius and the Princess III(母函数)
- HDU1028 Ignatius and the Princess III(母函数模板)
- 【母函数】hdu1028(Ignatius and the Princess III)
- hdu1028 Ignatius and the Princess III(母函数)
- 【HDU1028】Ignatius and the Princess III 母函数
- HDU1028 Ignatius and the Princess III(母函数)
- hdu1028 Ignatius and the Princess III
- (hdu1028)Ignatius and the Princess III
- hdu1028 Ignatius and the Princess III
- hdu1028-Ignatius and the Princess III
- android 百度地图sdk v3.4 绘制历史轨迹
- Codeforece Gym 100500BConference Room
- UIView常用的一些方法小记之setNeedsDisplay和setNeedsLayout
- 如何定位和解决Andorid的内存溢出问题(大总结)
- Oracle数据导入导出之葵花宝典-Excel篇
- HDU1028 Ignatius and the Princess III【母函数】【完全背包】
- 待解决
- MATLAB学习笔记(一)
- 各种颜色代码
- 欧拉计划3
- LintCode-第k个排列
- WebService(4)——WSDL文档解析
- 判断是不是闰年问题
- 关于计算机基础常识