Ignatius and the Princess III

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

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
 
 
递归
#include<stdio.h>
#include<string.h>
const int MAXN=;
int dp[MAXN][MAXN];//用数组记录计算结果,节约时间
//dp[i][j]表示将i分成j部分的和等于i的方法数
int calc(int n,int m)
{
if(dp[n][m]!=-)
return dp[n][m];
if(n<||m<)
return dp[n][m]=;
if(n==||m==)
return dp[n][m]=;
if(n<m)
return dp[n][m]=calc(n,n);
if(n==m)
return dp[n][m]=calc(n,m-)+;
return dp[n][m]=calc(n,m-)+calc(n-m,m); }
int main()
{
int n;
memset(dp,-,sizeof(dp));
while(scanf("%d",&n)!=EOF)
printf("%d\n",calc(n,n));
return ;
}

DP

#include<iostream>
using namespace std;
int main()
{
int n;
while (cin >> n)
{
int dp[] = { };
dp[] = ;
for (int i = ; i <= n; i++)//分成几部分
{
for (int j = i; j <= n; j++)//每一部分先放1个有dp[j]种放法,剩下的j-i个随便放有dp[j-i]种放法
{
dp[j] = dp[j] + dp[j - i];//不断更新
}
}
cout << dp[n] << endl;
}
}

hdu1028 Ignatius and the Princess III(递归、DP)的更多相关文章

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

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

  2. HDU1028 Ignatius and the Princess III 【母函数模板题】

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

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

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

  4. HDU 1028 Ignatius and the Princess III:dp or 母函数

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1028 题意: 给你一个正整数n,将n拆分成若干个正整数之和,问你有多少种方案. 注:"4 = ...

  5. hdu1028 Ignatius and the Princess III

    这是道典型的母函数的题目,可以看看我的母函数这一标签上的另一道例题,里面对母函数做了较为详细的总结.这题仅贴上代码: #include"iostream" using namesp ...

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

    题意 给出$n$,问用$1$到$n$的数字问能构成$n$的方案数 思路 生成函数基础题,$x^{n}$的系数即答案. 代码 #include <bits/stdc++.h> #define ...

  7. hdu1028 Ignatius and the Princess III(生成函数整理占坑)upd 已咕

    先咕着 ---------------2018 5 22---------------------- 题解 生成函数处理整数拆分 code #include<cstdio> #includ ...

  8. 【母函数】hdu1028 Ignatius and the Princess III

    大意是给你1个整数n,问你能拆成多少种正整数组合.比如4有5种: 4 = 4;  4 = 3 + 1;  4 = 2 + 2;  4 = 2 + 1 + 1;  4 = 1 + 1 + 1 + 1; ...

  9. ACM学习历程—HDU1028 Ignatius and the Princess III(递推 || 母函数)

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

随机推荐

  1. 请用fontAwesome代替网页icon小图标(转)

    1. 引言 网页小图标到处可见,如果一个网页都是干巴巴的文字和图片,而没有小图标,会显得非常简陋.下面的小图标,你是不是会经常用到? 你可能说——“我们用的都是彩色的,不是黑白的”——别着急,下面会讲 ...

  2. POJ 1191 棋盘分割 (区间DP,记忆化搜索)

    题面 思路:分析公式,我们可以发现平均值那一项和我们怎么分的具体方案无关,影响答案的是每个矩阵的矩阵和的平方,由于数据很小,我们可以预处理出每个矩阵的和的平方,执行状态转移. 设dp[l1][r1][ ...

  3. Luogu 4001 [BJOI2006]狼抓兔子

    BZOJ 1001…… 并不会这个trick,所以笔记要详细一点. 前置知识 : 平面图转对偶图    传送门 听说直接$Dinic$就好了,还跑得比正解快…… 首先我们按照平面图的定义,把网格图中所 ...

  4. Entity Framework Tutorial Basics(11):Code First

    Code First development with Entity Framework: Entity Framework supports three different development ...

  5. java全栈day34---表单CSS

    今日内容介绍 1 使用html的表单标签编写“注册页面” 2 使用DIV和CSS重写网站首页 所有的html标签中,表单标签是最重要的.在实际开发中,最经典的实例就是用户注册,覆盖 了表单标签的所有的 ...

  6. java全栈day02

    今日内容介绍1.变量2.运算符 01变量概述 * A: 什么是变量? * a: 变量是一个内存中的小盒子(小容器),容器是什么?生活中也有很多容器,例如水杯是容器,用来装载水:那么变量是装载什么的呢? ...

  7. Linux系统命令Top/free的使用及参数详解

    1.作用 top命令用来显示执行中的程序进程,使用权限是所有用户. 2.格式 top [-] [d delay] [q] [c] [S] [s] [i] [n] 3.主要参数 d:指定更新的间隔,以秒 ...

  8. 解决ScrollView嵌套viewpager滑动事件冲突问题

    重写ScrollView 第一种方案能解决viewpager的滑动问题,但是scrollView有时会滑不动 public class VerticalScrollView extends Scrol ...

  9. Android之九宫格解锁的实现

        <ignore_js_op>                                                  下面是最重要的那个LocusPassWordView ...

  10. Data Base System.Data.OracleClient requires Oracle client software version 8.1.7 or greater解决方案

    System.Data.OracleClient requires Oracle client software version 8.1.7 or greater解决方案 一.问题: 1.通过Syst ...