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. Quartz contention when running in load balanced environment--reference

    1.8.3 appears to have addressed this issue with a single application server. However, we're seeing t ...

  2. Android(java)学习笔记240:多媒体之图形颜色的变化

    1.相信大家都用过美图秀秀中如下的功能,调整颜色: 2. 下面通过案例说明Android中如何调色: 颜色矩阵 ColorMatrix cm = new ColorMatrix(); paint.se ...

  3. 【IOS】 XML解析和xml转plist文件(GDataXML)

    iOS对于XML的解析有系统自带的SDK--NSXMLParser,鄙人愚拙,只会用GDataXML进行解析,这里仅介绍GData的使用.(以下图为例) 1.对于一个xml文件,先读取出来 NSDat ...

  4. codevs 1222 信与信封问题

    /* 二分图 题目给出的是确定不连通的边 如果我们拿剩下的可能联通也可能不连通的边跑最大匹配 如果不是完美非配 也就是说把所有可能的边都认为是一定的 这样都跑不出来(不能匹配到每个点)那么一定不能确定 ...

  5. Android开发手记(23) Notification

    有时候,我们需要应用程序在状态内显示一些通知信息,这时我们就需要使用Notification来完成这一工作.也许我们会想到以前经常使用的Toast来通知用户.虽然Notification与Toast都 ...

  6. nodejs原生模块简介

    一.Express框架 前面的章节已经介绍过了,可以使用npm来安装node.js模块.具体操作请参照以前写的nodejs概论. Express是一个nodejs的web开源框架,用于快速的搭建web ...

  7. PHP json的插入和解析在数据库中的操作

    JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它基于ECMAScript的一个子集. PHP中往数据库中存储json数据在项目开发中也经常遇到,下面我就 ...

  8. Python 3中bytes和str的分别

    最近把一段py2的代码转换到py3的代码,结果运行到向socket中写数据的代码部分出现了'str' does not support the buffer interface这样一个错误. 一番搜索 ...

  9. css3之box-sizing

    css盒子模型中包括几种重要的属性,包括margin.border.padding以及content.但浏览器对其盒子模型的解释则有所不痛,启用标准模式还是IE(怪)模式是与当前页面的文档声明相关的. ...

  10. Build Android-x86 ICS 4 Virtualbox from Google Virtualbox Target and Intel Kernel 编译体验

    最近一直在研究android源码的编译,应该说研究的很辛苦,最难的是下源码,总是不停的断掉,最后感谢公司的高网速,找到方法后12G的源码只花了1个小时就下完了. 参考以下网址:http://softw ...