题目:

"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!" 

InputThe 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. 
OutputFor 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

题意分析:

这题是对母函数的另一个应用,整数的拆分。

我们可以把每个数的数值当作母函数经典例题中的砝码的质量。然后把需要凑的总数值当作砝码需要称的质量,这题就比较好理解了。

打表,控制指数在120以内。

AC代码:

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int MAXN = 120;
int C1[MAXN+3], C2[MAXN+3]; void solve()
{
int i, j, k;
for(i = 0; i <= MAXN; i++)
{
C1[i] = 1;
C2[i] = 0;
}
for(i = 2; i <= MAXN; i++)
{
for(j = 0; j <= MAXN; j++)
{
for(k = 0; k+j <= MAXN; k+=i)
{
C2[k+j] += C1[j];
}
}
for(j = 0; j <= MAXN; j++)
{
C1[j] = C2[j];
C2[j] = 0;
}
}
} int main()
{
int N;
solve();
while(scanf("%d", &N)!=EOF)
{
printf("%d\n", C1[N]);
}
return 0;
}

  

HDU_1028 Ignatius and the Princess III 【母函数的应用之整数拆分】的更多相关文章

  1. 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 母函数

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

  3. hdu 1028 Sample Ignatius and the Princess III (母函数)

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

  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. Ignatius and the Princess III HDU - 1028 || 整数拆分,母函数

    Ignatius and the Princess III HDU - 1028 整数划分问题 假的dp(复杂度不对) #include<cstdio> #include<cstri ...

  6. HDOJ 1028 Ignatius and the Princess III (母函数)

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

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

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

  8. Ignatius and the Princess III(杭电1028)(母函数)

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

  9. hdu acm 1028 数字拆分Ignatius and the Princess III

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

随机推荐

  1. Android selector中的item的顺序

    在selector中,要将默认状态的item放在最后面,因为一旦前面的item满足匹配条件,后面的item就不会去匹配.因此,把默认状态的item放在前面的话,后面的item没有执行的机会

  2. opencv掩膜操作

    #include <iostream>#include <opencv2/opencv.hpp> using namespace std;using namespace cv; ...

  3. Yii2验证登录得User类

    Yii2中的  Class yii\web\User 是如果进行验证登录,如果我们使用User类验证登录会给我们减少很多麻烦.在此就拿Yii2中自带的登录功能进行说明. 配置.在应用配置文件compo ...

  4. JavaScript——Dom编程(2)

    ①.创建一个元素节点: var reference = document.createElement(element) createElement(): 按照给定的标签名创建一个新的元素节点. 方法只 ...

  5. 如何看待那些不能重现的bug?

    在我们日常测试活动中,经常会发现一些bug,但是这些bug可能就是昙花一现,再也无法(或者很难)重现出来,内心灰常崩溃.那到底有哪些方面可能会导致这类的缺陷发生呢? 我以自己工作中所遇到的给出一些自己 ...

  6. 使用Adobe Illustrator + ArcGIS绘制地图 | Map Design Using ArcGIS + Adobe Illustrator

    国内GIS/Cartography同行大部分使用CorelDraw绘制地图.相比之下,国外同行则更多使用Adobe Illustrator绘制地图.CorelDraw和Illustrator两个软件均 ...

  7. 设计模式10: Facade 外观模式(结构型模式)

    Facade 外观模式(结构型模式) 系统的复杂度 假设我们要开发一个坦克模式系统用于模拟坦克车在各种作战环境中的行为,其中坦克系统由引擎.控制器.车轮.车身等各个子系统构成. internal cl ...

  8. HTML5和CSS3实例教程 中文版 高清PDF扫描版

    HTML5和CSS3实例教程共分3部分,集中讨论了HTML5和CSS3规范及其技术的使用方法.首先是规范概述,介绍了新的结构化标签.表单域及其功能(包括自动聚焦功能和占位文本)和CSS3的新选择器.接 ...

  9. Nexus 私有仓库

    Nexus3.6和Nexus2.x安装不同,2.x版本需要安装服务,再启动.而3.6版本则更加简单. 步骤如下: jdk环境:1.8 Nexus3.6解压(注意,路径不要带空格及中文),解压后有两个文 ...

  10. React + Python 七月小说网 启程(一)

    一.为啥要做这个网站 很久没有写技术相关的博客了,最近几个月忙飞,各种工作,技术根本学不完,很难受. 趁着春节期间,终于有空闲时间做自己爱做的事情了,美滋滋. 热爱技术,热爱小说,于是诞生了个这么玩意 ...