HDU 1028(Ignatius and the Princess III)区间DP之整数划分
来源:互联网 发布:三滴水一个乎 编辑:程序博客网 时间:2024/06/16 06:03
区间DP整数划分题,自己的区间DP比较菜,云里雾里,方程不会推。
一看题就知道要打表了,n=120.
当n<m时,由于分法不可能出现负数,所以record[n][m]=record[n][n];当n==m时,那么就得分析是否要分出m这一个数,如果要分那就只有一种{m},要是不分,那就是把n分成不大于m-1的若干份;即record[n][n]=1+record[n][n-1];当n>m时,那么就得分析是否要分出m这一个数,如果要分那就{{m},{x1,x2,x3..}}时n-m的分法record[n-m][m],要是不分,那就是把n分成不大于m-1的若干份; 即record[n][n]=record[n-m][m]+record[n][m-1];
这是看了别人的解题报告的,哎。record[i][j]代表,分解第i个数最大数为j的分法数量,j>i,当然和record[i][i]相同了,i不能分解成j+某个数了。
代码:
#include<stdio.h>#include<string.h>int dp[125][125];int main(){ int i,j,n; for(i=1;i<=120;i++) { dp[1][i]=1; dp[i][1]=1; dp[0][i]=1; } for(i=2;i<=120;i++) { for(j=2;j<=120;j++) { if(j>i) dp[i][j]=dp[i][i]; else { dp[i][j]=dp[i-j][j]+dp[i][j-1]; } } } while(scanf("%d",&n)!=EOF) { printf("%d\n",dp[n][n]); } return 0; }
0 0
- HDU 1028(Ignatius and the Princess III)区间DP之整数划分
- hdu 1028Ignatius and the Princess III(整数划分)
- hdu 1028 Ignatius and the Princess III(整数划分)
- hdu 1028 Ignatius and the Princess III 【整数划分】
- hdu 1028 Ignatius and the Princess III 整数划分+dp 组合
- HDU 1028 Ignatius and the Princess III(母函数 或者 整数划分的DP动态规划)
- HDU 1028 Ignatius and the Princess III(DP,整数划分)
- hdu1028 Ignatius and the Princess III(DP整数划分)
- hdu 1208 Ignatius and the Princess III 划分数,dp
- HDOJ 1028 Ignatius and the Princess III(整数划分)
- Hdu 1028 Ignatius and the Princess III//整数划分(一)
- 【HDU 1028】【母函数 整数划分】Ignatius and the Princess III
- hdu 1028 Ignatius and the Princess III(整数的划分)
- HDU 1028 Ignatius and the Princess III 整数的拆分
- HDU 1028 Ignatius and the Princess III【整数拆分】
- hdu 1028 Ignatius and the Princess III (整数拆分)
- hdu 1028 Ignatius and the Princess III 整数拆分 母函数/dp
- Hdu 1028 Ignatius and the Princess III(整数拆分问题,DP)
- RMQ算法 快速求区间最大最小值
- 自动布局Cell
- 线段覆盖长度
- HTML页面插入Flash动画及背景音乐
- POJ 1463 Strategic game
- HDU 1028(Ignatius and the Princess III)区间DP之整数划分
- 多个maven项目集成
- 查找文件,并按时间排序
- NYOJ 216 A problem is easy
- 2014阿里巴巴9月14北京校园招聘笔试及参考答案
- hdu 1885 Key Task(bfs+状态压缩)
- 51nod1117
- 使用golang的标准库搭建网站--1.从最简单的页面开始
- WebRTC在Windows下的编译过程