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. 完美解决Android完全退出程序(转)

    背景:假说有两个Activity, Activity1和Activity2, 1跳转到2,如果要在2退出程序,一般网上比较常见的说法是用 System.exit(0) 或是 android.os.Pr ...

  2. POJ 3162 Walking Race(树的直径+单调队列)

    题目大意:对一棵树,求出从每个结点出发能到走的最长距离(每个结点最多只能经过一次),将这些距离按排成一个数组得到dis[1],dis[2],dis[3]……dis[n] ,在数列的dis中求一个最长的 ...

  3. ADLINK 8158控制程序-连续运动(VB.NET)

    运动平台:日脉的二维运动平台(一个旋转平台和一个滑动平台) 开发环境:VS2010 + .NET Framework + VB.NET 使用文件:pci_8158.vb motion_8158_2D. ...

  4. 获取html页面所有的img标签

    #region 获取html中所有Img Regex r = new Regex(@"<img[\s\S]*?>", RegexOptions.IgnoreCase); ...

  5. php 在web端读出pdf 与各种文件下载

    单纯的下载功能实现 <?php // 表示调用文本类型为pdf的应用 header('Content-type: application/pdf'); // 这句可以输出下载页面进行下载 hea ...

  6. 《第一行代码》学习笔记1-Android系统架构

    1. 2003.10,Andy Rubin创办Android公司.2005.8,Google收购之,并于2008年推出Android系统第一个版本. 2. ①Linux Kernel:基于Linux ...

  7. ORACLE调度之基于事件的调度(二)【weber出品】

    一.回顾 调度分基于时间的调度和基于事件的调度. 稍微复习一下前面的只是请浏览:<ORACLE调度之基于时间的调度(一)[weber出品]> 二.知识补充 1.队列:一种数据结构,就像一根 ...

  8. jquery $.each遍历json数组方法

    <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/ ...

  9. Javascript数组方法探究一二

    1. Array.prototype.slice方法 数组的 slice 方法通常用来从一个数组中抽取片断.不过,它还有将“类数组”(比如arguments和​HTMLCollection​)转换为真 ...

  10. AMD和CMD的区别

    1.cmd define(function(require,export){ var b = 1; var a = require('./a'); a.dosomething(); }); 2.amd ...