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!”

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

4

10

20

Sample Output

5

42

627


思路:

(i,j)(i>=j)代表的含义是i为n,j为划分的最大的数字。

边界:a(i,0) = a(i, 1) = a(0, i) = a(1, i) = 1;

i|j==0时,无论如何划分,结果为1;

当(i>=j)时,

划分为{j,{x1,x2…xi}},{x1,x2,…xi}的和为i-j,

{x1,x2,…xi}可能再次出现j,所以是(i-j)的j划分,所以划分个数为a(i-j,j);

划分个数还需要加上a(i,j-1)(累加前面的);

当(i < j)时,

a[i][j]就等于a[i][i];

import java.util.Scanner;

public class Main{
static int a[][] = new int[125][125];
public static void main(String[] args) {
dabiao(); Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int n = sc.nextInt();
System.out.println(a[n][n]);
}
} private static void dabiao() {
for(int i=0;i<121;i++){
a[i][0]=1;
a[i][1]=1;
a[0][i]=1;
a[1][i]=1;
}
for(int i=2;i<121;i++){
for(int j=2;j<121;j++){
if(j<=i){
a[i][j]=a[i][j-1]+a[i-j][j];
}else{
a[i][j]=a[i][i];
}
}
}
}
}

HDOJ 1028 Ignatius and the Princess III(递推)的更多相关文章

  1. HDOJ 1028 Ignatius and the Princess III (母函数)

    Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  2. hdoj 1028 Ignatius and the Princess III(区间dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1028 思路分析:该问题要求求出某个整数能够被划分为多少个整数之和(如 4 = 2 + 2, 4 = 2 ...

  3. hdu 1028 Ignatius and the Princess III 简单dp

    题目链接:hdu 1028 Ignatius and the Princess III 题意:对于给定的n,问有多少种组成方式 思路:dp[i][j],i表示要求的数,j表示组成i的最大值,最后答案是 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. hdu 1028 Ignatius and the Princess III 母函数

    Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  8. hdu 1028 Ignatius and the Princess III (n的划分)

    Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  9. HDU 1028 Ignatius and the Princess III伊格和公主III(AC代码)母函数

    题意: 输入一个数n,求组合成此数字可以有多少种方法,每一方法是不记录排列顺序的.用来组成的数字可以有1.2.3....n.比如n个1组成了n,一个n也组成n.这就算两种.1=1,2=1+1=2,3= ...

随机推荐

  1. linux 下 apt命令集详解

    apt命令用法 packagename指代为软件包的名称 apt-get update 在修改/etc/apt/sources.list或/etc/apt/preferences之後运行该命令.此外您 ...

  2. 有向图的欧拉路径POJ2337

    每个单词可以看做一条边,每个字母就是顶点. 有向图欧拉回路的判定,首先判断入度和出度,其实这个题判定的是欧拉通路,不一定非得构成环,所以可以有一个点的顶点入度比出度大1,另外一个点的出度比入度大1,或 ...

  3. AlertDialog dismiss 和 cancel方法的区别

    AlertDialog使用很方便,但是有一个问题就是:dismiss方法和cancel方法到底有什么不同? AlertDialog继承与Dialog,现在各位看看结构图: 然后在Dialog类中找到了 ...

  4. java计算两个日期之间相隔的天数

    import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; impor ...

  5. ASPNET5应用程序启动

    1. 启动类 在asp.net5当中,Startup类提供应用程序的入口,对所有应用程序是必须的.争对特定环境的配置的starup class和方法也是有可能的, 但是,不管怎样, 一个Startup ...

  6. [转帖]AVS音视频编解码技术了解

    AVS高清立体视频编码器 电视技术在经历了从黑白到彩色.从模拟到数字的技术变革之后正在酝酿另一场技术革命,从单纯观看二维场景的平面电视跨越到展现三维场景的立体电视3DTV.3DTV系统的核心问题之一是 ...

  7. linux 命令及进程控制

    main.c  main.o/main.obj  main/main.exe          编译                连接 程序运行;      两步: gcc/g++  -c  mai ...

  8. [LeetCode OJ] Candy

    There are N children standing in a line. Each child is assigned a rating value. You are giving candi ...

  9. Thinkphp发布文章获取第一张图片为缩略图实现方法

    正则匹配图片地址获取第一张图片地址 此为函数 在模块或是全局Common文件夹中的function.php中 /** * [getPic description] * 获取文本中首张图片地址 * @p ...

  10. weekly review

    鉴于某位昔日工作在我身边的大师一直在写review,所以为了能靠近大师,我也要开始写review了. 无名师曾经说过,想要成为大师的话,要先找到一个大师,然后追随大师,再然后与大师通行,之后成为大师, ...