Ignatius and the Princess III

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

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
题目大意:
求n有几种划分(3=1+2和3=2+1是同一种划分方案)。
 
dp[i][j]表示i分为j块一共有几种方案。
那么,一般的,考虑划分的j块中有多少个1,接着用截边法处理:
若有0个1,把这j块都减一,转化为i-j分为j块,dp[i][j]+=dp[i-j][j];
若有1个1,把这j块都减一,转化为i-j分为j-1块,dp[i][j]+=dp[i-j][j-1];
一直考虑到有k个1即可。
每个数的划分数即为sum dp[i][]。
 
#include <cstdio>
#include <cstring> using namespace std; const int maxn=; //动规打表
int dp[maxn+][maxn+]; int sum[maxn+]; int main()
{
memset(dp,,sizeof(dp));
memset(sum,,sizeof(sum));
for(int i=;i<=maxn;++i)
{
dp[i][]=dp[i][i]=;
for(int j=;j<=i-;++j)
{
for(int k=;k<=j;++k)
{
dp[i][j]+=dp[i-j][j-k];
}
}
for(int j=;j<=i;++j)
{
sum[i]+=dp[i][j];
}
} int n;
while(scanf("%d",&n)!=EOF)
{
printf("%d\n",sum[n]);
} return ;
}

hdu 1028 Ignatius and the Princess III (n的划分)的更多相关文章

  1. HDU 1028 Ignatius and the Princess III dp整数划分

    http://acm.hdu.edu.cn/showproblem.php?pid=1028 dp[i][j]表示数值为i,然后最小拆分的那个数是j的时候的总和. 1 = 1 2 = 1 + 1 . ...

  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 (母函数或者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 母函数

    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 (递归,dp)

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

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

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

  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. [FPGA]Verilog实现8位串并转换器HC595

    目录 想说的话... 正文 IC介绍_HC595 电路连接图 功能表 逻辑图 代码实现 代码已经更新,新的代码按照电路编写,忠实于原电路的逻辑,已注于文末(11/16) 修复并行输出数据出错的bug, ...

  2. python中return和print的区别

    之前遇到这个问题,就试着对比几种不同的结果,总结啦一下return和print的区别. 总结: return的作用之一是返回计算的值print的作用是输出数据到控制端 在第一个结果中什么都没有输出:在 ...

  3. vCenter Server Appliance(VCSA )6.7部署指南

    目录 简介 环境准备 开始安装 第一阶段安装 第二阶段安装 使用 简介 早期的VCSA支持 SUSE 和 Windows,不太懂SUSE,也不想用Windows 而在2018年4月17日VCSA 6. ...

  4. CentOS 7 Cobbler 自动化安装系统

    在上一篇Cobbler 安装中,配置好了Cobbler,下面来配置自动化安装 配置cobbler-DHCP # 修改settings中参数,由cobbler控制dhcp [root@cobbler ~ ...

  5. iptables filter表案例、iptables nat表应用 使用介绍

    第7周第4次课(5月10日) 课程内容: 10.15 iptables filter表案例10.16/10.17/10.18 iptables nat表应用 扩展1. iptables应用在一个网段 ...

  6. MySQL主从扩展知识

    6月29/7月2日任务 说明:这两天无新课,主要是扩充知识面注意:这两天的任务,需要回专贴.需要你们通过看这些东西总结成自己的心得. 不能照搬,必须要自己理解,能看多少就看多少,看不完也没有关系,但一 ...

  7. HC大会,华为联合合作伙伴发布一站式物联网IoT开发工具小熊派BearPi

    传统的物联网产品开发步骤复杂,涉及硬件开发.软件开发.云端开发等众多流程.而且产品的开发周期长.开发成本高.产品稳定性不佳.维护成本高.而物联网设备本身市场竞争激烈,价格低,设备更新迭代快,所以在保证 ...

  8. 【转载】Dockerfile文件详解

    什么是dockerfile? Dockerfile是一个包含用于组合映像的命令的文本文档.可以使用在命令行中调用任何命令. Docker通过读取Dockerfile中的指令自动生成映像. docker ...

  9. HDU 6405 Make ZYB Happy(广义SAM)

    It's known to all that ZYB is godlike, so obviously he has a large number of titles, such as jskingj ...

  10. ACM-ICPC 2018 焦作赛区网络预赛J题 Participate in E-sports

    Jessie and Justin want to participate in e-sports. E-sports contain many games, but they don't know ...