题目:

"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. linux c 获取系统时间

    #include <time.h> main() { time_t timep; time (&timep); printf(“%s”,asctime(gmtime(&ti ...

  2. Yii2邮箱发送与配置

    1配置邮箱 在 common/config/web.php中写入以下代码配置 Mail代理 return [ 'components' => [ ...//your code, //以下是 ma ...

  3. Django----配置数据库读写分离

    Django配置数据库读写分离 https://blog.csdn.net/Ayhan_huang/article/details/78784486 https://blog.csdn.net/ayh ...

  4. Win7怎么进入安全模式 三种轻松进入Win7安全模式方法

    发布时间:2013-05-27 11:23 作者:电脑百事网原创 来源:www.pc841.com 13783次阅读 win7的安全模式和XP如出一辙,在安全模式里我们可以删除顽固文件.查杀病毒.解除 ...

  5. ssh试卷

    2.简述Hibernate的工作原理. 答:首先,Configuration读取Hibernate的配置文件及映射文件中的信息,即加载配置文件和映射文件,并通过Hibernate配置文件生成一个多线程 ...

  6. - Unknown tag (c:set).

    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

  7. Java Thread.join()详解--父线程等待子线程结束后再结束

    目录(?)[+] 阅读目录 一.使用方式. 二.为什么要用join()方法 三.join方法的作用 join 四.用实例来理解 打印结果: 打印结果: 五.从源码看join()方法   join是Th ...

  8. DELPHI XE5 UP2 运行IOS 遇到 Wrapper init failed: (null)问题的解决办法

    一.问题表现: 在MAC OSX(10.9.2)上安装了比较新的XCODE5.1 和COMMAND LINE TOOLS 在DELPHI XE5 UP2上放了一个按钮,输出到MAC OSX上,出现: ...

  9. C# Task的使用

    1.Task的使用 创建一个Task,有三种方式 //第一种 Task t1 = new Task(() => { Console.WriteLine(DateTime.Now.ToString ...

  10. Vue Vuex state mutations

    Vuex 解决不同组件的数据共享,与数据持久化 1.npm install vuex --save 2.新建store.js 并引入vue vuex ,Vue.use(Vuex) 3.state在vu ...