题目:

"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. 598. Range Addition II 矩阵的范围叠加

    [抄题]: Given an m * n matrix M initialized with all 0's and several update operations. Operations are ...

  2. hibernate 一对多(级联关系)

    hibernate 核心配置文件 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hiber ...

  3. Hadoop完全分布式环境搭建(四)——基于Ubuntu16.04安装和配置Hadoop大数据环境

    [系统环境] [安装配置概要] 1.上传hadoop安装文件到主节点机器 2.给文件夹设置权限 3.解压 4.拷贝到目标文件夹 放在/opt文件夹下,目录结构:/opt/hadoop/hadoop-2 ...

  4. Hibernate和Mybatis区别 详细 有用

    1.开发上手难度 hibernate的真正掌握(封装的功能和特性非常多)要比Mybatis来得难. 在真正产品级应用上要用Hibernate,不仅对开发人员的要求高,hibernate往往还不适合(多 ...

  5. hdu 4681 String(转载)

    #include <stdio.h> #include <string.h> #include <algorithm> #include <iostream& ...

  6. Monkey稳定性测试环境搭建说明

    一.安装Java环境 安装Java环境-JDK:下载地址:http://pan.baidu.com/s/1pJ6Yqs7,jdk安装解压即可. 二.设置环境变量 双击下载的JDK ,设置安装路径.这里 ...

  7. 编写高质量代码改善C#程序的157个建议——建议24:迭代器应该是只读的

    建议24:迭代器应该是只读的 如果注意观察会发现,FCL中的迭代器只有GetEnumerator方法,没有SetEnumerator方法,所有的集合类也没有一个可以写的迭代器属性.原因有二: 一:这违 ...

  8. 设计模式11: Flyweight 享元模式(结构型模式)

    Flyweight 享元模式(结构型模式) 面向对象的代价 面向对象很好的解决了系统抽象性的问题,同时在大多数情况下也不会损及系统的性能.但是,在某些特殊应用中,由于对象的数量太大,采用面向对象会给系 ...

  9. SQL Server 根据关键字和结束符提取字符串子串

    /* @info-待截取的字符串 @indexStr-截取子串的起始字符串 @split-截取子串的结束符号 列入依次传入 胸片:正常.心电图:异常,需要注意.血常规检查:正常. 心电图 '.' 返回 ...

  10. 个人JS体系整理(三)

    一. 严格模式 JavaScript 严格模式(strict mode)即在严格的条件下运行.首先声明,严格模式是ES5中提出来的,准确来说就是一句指令Use strict,它的目的是指定代码在严格条 ...