HDU 1028 Ignatius and the Princess III
来源:互联网 发布:java经纬度坐标范围内 编辑:程序博客网 时间:2024/05/01 05:06
Problem Description
"Well, it seems the first problem is too easy. I will let you know how foolish you are later." feng5166 says.
"The second problem is, given an positive integer N, we define an equation like this:
N=a[1]+a[2]+a[3]+...+a[m];
a[i]>0,1<=m<=N;
My question is how many different equations you can find for a given N.
For example, assume N is 4, we can find:
4 = 4;
4 = 3 + 1;
4 = 2 + 2;
4 = 2 + 1 + 1;
4 = 1 + 1 + 1 + 1;
so the result is 5 when N is 4. Note that "4 = 3 + 1" and "4 = 1 + 3" is the same in this problem. Now, you do it!"
"The second problem is, given an positive integer N, we define an equation like this:
N=a[1]+a[2]+a[3]+...+a[m];
a[i]>0,1<=m<=N;
My question is how many different equations you can find for a given N.
For example, assume N is 4, we can find:
4 = 4;
4 = 3 + 1;
4 = 2 + 2;
4 = 2 + 1 + 1;
4 = 1 + 1 + 1 + 1;
so the result is 5 when N is 4. Note that "4 = 3 + 1" and "4 = 1 + 3" is the same in this problem. Now, you do it!"
Input
The input contains several test cases. Each test case contains a positive integer N(1<=N<=120) which is mentioned above. The input is terminated by the end of file.
Output
For each test case, you have to output a line contains an integer P which indicate the different equations you have found.
Sample Input
41020
Sample Output
542627经典DP#include<stdio.h>#include<string.h>const int MAXN=130;int dp[MAXN][MAXN];int calc(int n,int m){ if(dp[n][m]!=-1) return dp[n][m]; if(n<1||m<1) return dp[n][m]=0; if(n==1||m==1) return dp[n][m]=1; if(n<m) return dp[n][m]=calc(n,n); if(n==m) return dp[n][m]=calc(n,m-1)+1; return dp[n][m]=calc(n,m-1)+calc(n-m,m); } int main(){ int n; memset(dp,-1,sizeof(dp)); while(scanf("%d",&n)!=EOF) printf("%d\n",calc(n,n)); return 33;}
0 0
- 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
- 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
- hdu 1028 Ignatius and the Princess III
- HDU--1028 Ignatius and the Princess III
- HDU 1028 Ignatius and the Princess III
- Ignatius and the Princess III hdu 1028
- 每天一个linux命令(60):scp命令
- SVM - 手写数字识别
- Hibernate3学习笔记(10)——ID 标识选择器
- 对程序员非常重要的24个软技能
- 【C语言】02-第一个C程序
- HDU 1028 Ignatius and the Princess III
- SpringMVC第一个实例
- 第十六周
- Mac环境下svn的使用
- Unity5.1 新的网络引擎UNET(九) UNET 官方推荐视频教程
- 第十七周
- 每天一个linux命令(61):wget命令
- Java基础练习选择题(1)答案已整理
- Remove Duplicates from Sorted List II