HDOJ 1028 Ignatius and the Princess III(递推)
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(递推)的更多相关文章
- HDOJ 1028 Ignatius and the Princess III (母函数)
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- hdoj 1028 Ignatius and the Princess III(区间dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1028 思路分析:该问题要求求出某个整数能够被划分为多少个整数之和(如 4 = 2 + 2, 4 = 2 ...
- hdu 1028 Ignatius and the Princess III 简单dp
题目链接:hdu 1028 Ignatius and the Princess III 题意:对于给定的n,问有多少种组成方式 思路:dp[i][j],i表示要求的数,j表示组成i的最大值,最后答案是 ...
- 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 ...
- 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 ...
- 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 ...
- hdu 1028 Ignatius and the Princess III 母函数
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- 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 ...
- 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= ...
随机推荐
- Linux驱动程序开发 - 设备控制接口
(2008-08-08 15:02:19) 转载▼ 标签: it linux kernel driver 分类: Linux 序言设备驱动程序的一个基本功能就是管理和控制设备,同时为用户应用程序提供管 ...
- Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace.(转)
1.程序运行后异常显示: 解决方案:在项目上点击右键->properties->Java Build Path, remove掉Android Dependences即可
- picasso_强大的Android图片下载缓存库
tag: android pic skill date: 2016/07/09 title: picasso-强大的Android图片下载缓存库 [本文转载自:泡在网上的日子 参考:http://bl ...
- 向量旋转 UPC 2217
这道题目是13山东省省赛的签到题,题目大意是给等边三角形的两个定点,让求逆时针旋转之后的第三个点的坐标,原来不会向量的旋转,在网上找了找,找到一篇挺好的,直接贴过来. 向量的旋转 实际做题中我们可能会 ...
- verilog之task用法实例
该用法的代码源自夏宇闻老师的教材. 源代码: module traffic_lights; reg clock, red, amber, green; , off = , red_tics = , a ...
- 【开源java游戏框架libgdx专题】-10-核心库-Viewport
Viewport类,又称为视口类,主要负责管理游戏相机,处理游戏世界坐标与布景层坐标的换算关系.在移动端开发,不像PC端容易.因为要适配不同分辨率的设备.libgdx处理不同的设备屏幕时,用视口处理舞 ...
- javascript 获取用户光标,插入文本
图1 如图1所示,点击[函数名称],将函数名称添加到表达式内容框中,点击参数名称,将参数名称index1作为方法的参数添加到表达式内容中的表达式中. 该功能实现主要是采用了javascript获取鼠标 ...
- eclipse中启动tomcat
0.以下即使部署好,点小猫启动tomcat,有一个问题,修改jsp文件,本地tomcat中的此jsp并没有修改,如果右键项目启动,则会修改,不知道为什么 1. 首先发布项目,项目右键,run serv ...
- codevs 1139 观光公交
#include<cstdio> #include<cstdlib> #include<cstring> #define max(a,b) (a > b ? ...
- Android JNI 之 环境安装
在配置环境之前,我们得了解 JNI 和NDK JNI JNI是Java Native Interface的缩写,中文为JAVA本地调用.它提供了若干的API实现了和Java和其他语言的通信(主要是C& ...