Ignatius and the Princess III

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 15942    Accepted Submission(s): 11245

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
 
Author
Ignatius.L
 
Recommend
We have carefully selected several similar problems for you:  1085 1398 2152 1709 1059
 
一开始自己想了一种解法,类似dp,但是应该不是dp,应该算找规律,速度没dp快,因为多了一层循环,虽然最里面一层循环很小,
#include<queue>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
#define N 130
int n,d[N][N];//d[i][j]表示组成不超过j的数组成i有多少种方法 int main()
{
for(int i=;i<=;i++)d[i][]=;
d[][]=;
for(int i=;i<=;i++)
{
for(int j=;j<=i;j++)
{
for(int k=j;k>=;k--)
{
d[i][j]+=d[i-k][min(i-k,k)];
}
}
}
while(~scanf("%d",&n))
{
cout<<d[n][n]<<endl;
}
return ;
}

看了网上的正规dp解法,稍加改进

#include<queue>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
#define N 130
int n,d[N][N]; int main()
{
for(int i=;i<=;i++)d[i][]=;
d[][]=;
for(int i=;i<=;i++)
{
for(int j=;j<=i;j++)
{
d[i][j]=d[i][j-]+d[i-j][min(j,i-j)];
}
}
while(~scanf("%d",&n))
{
cout<<d[n][n]<<endl;
}
return ;
}

还有一种母函数的做法

以后再学习

HDU 1028 Ignatius and the Princess III (母函数或者dp,找规律,)的更多相关文章

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

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

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

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

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

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

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

  6. HDU 1028 Ignatius and the Princess III (生成函数/母函数)

    题目链接:HDU 1028 Problem Description "Well, it seems the first problem is too easy. I will let you ...

  7. 题解报告:hdu 1028 Ignatius and the Princess III(母函数or计数DP)

    Problem Description "Well, it seems the first problem is too easy. I will let you know how fool ...

  8. HDU 1028 Ignatius and the Princess III (递归,dp)

    以下引用部分全都来自:http://blog.csdn.net/ice_crazy/article/details/7478802  Ice—Crazy的专栏 分析: HDU 1028 摘: 本题的意 ...

  9. HDU 1028 Ignatius and the Princess III (动态规划)

    题目链接:HDU 1028 Problem Description "Well, it seems the first problem is too easy. I will let you ...

随机推荐

  1. debian 中的jdk

    1 openjdk 2 debian安装java的脚本 3 下载bin自己编译

  2. python基础-对象

    1. 对象:一组数据和操作数据方法的集合 >>> class Person(object): ...     def __init__(self,name): ...         ...

  3. 图论trainning-part-1 B. A Walk Through the Forest

    B. A Walk Through the Forest Time Limit: 1000ms Memory Limit: 32768KB 64-bit integer IO format: %I64 ...

  4. conda管理包

    清理 conda clean --lock --tarball --package (安装包) 安装或更新包 conda install numpy=1.9.3 conda update numpy= ...

  5. Flask+ Angularjs 实例: 创建博客

    允许任何用户注册 允许注册的用户登录 允许登录的用户创建博客 允许在首页展示博客 允许登录的用户退 后端 Flask-RESTful - Flask 的 RESTful 扩展 Flask-SQLAlc ...

  6. Laya Timer原理 & 源码解析

    Laya Timer原理 & 源码解析 @author ixenos 2019-03-18 16:26:38 一.原理 1.将所有Handler注册到池中 1.普通Handler在handle ...

  7. shell的case-esac

    case ... esac 与其他语言中的 switch ... case 语句类似,是一种多分枝选择结构. case 语句匹配一个值或一个模式,如果匹配成功,执行相匹配的命令.case语句格式如下: ...

  8. CocoaAsyncSocket一个第三方Socket库

    github地址:https://github.com/robbiehanson/CocoaAsyncSocket github上的不完整,cocochina也有demohttp://code4app ...

  9. 【边双连通】poj 3352 Road Construction

    http://poj.org/problem?id=3352 [题意] 给定一个连通的无向图,求最少加多少条边使得这个图变成边双连通图 [AC] //#include<bits/stdc++.h ...

  10. [暑假集训--数位dp]hdu3652 B-number

    A wqb-number, or B-number for short, is a non-negative integer whose decimal form contains the sub- ...