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

原创 2018年04月15日 19:28:40



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
41020
 

Sample Output
542627
 

Author
Ignatius.L


#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<iostream>
#include<math.h>
#include<queue>
#include<map>
#include<vector>
#include<set>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
int c1[130], c2[130];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        for(int i=0; i<=n; ++i)
        {
            c1[i] = 1;
            c2[i] = 0;
        }
        for(int i=2; i<=n; ++i)
        {
            for(int j=0; j<=n; ++j)
                for(int k=0; k+j<=n; k+=i)
                {
                    c2[k+j] += c1[j];
                }
            for(int j=0; j<=n; ++j)
            {
                c1[j] = c2[j];
                c2[j] = 0;
            }
        }
        printf("%d\n", c1[n]);
    }
    return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/dsaghjkye/article/details/79952125

hdu 1028 Ignatius and the Princess III(母函数,完全背包)

http://acm.hdu.edu.cn/showproblem.php?pid=1028 整数划分问题。 第一道母函数。。。 小于等于n的整数共有n个,1,2......n,每个数都有无限...
  • u013081425
  • u013081425
  • 2014-07-27 14:24:21
  • 1160

杭电 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...
  • lsgqjh
  • lsgqjh
  • 2015-04-25 09:43:49
  • 938

HDOJ 1028 Ignatius and the Princess III

链接:http://acm.hdu.edu.cn/showproblem.php?pid=1028 题目: Ignatius and the Princess III Time Limi...
  • u010084308
  • u010084308
  • 2014-06-30 16:02:42
  • 914

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

Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K...
  • jk13171217
  • jk13171217
  • 2014-07-30 17:11:07
  • 867

B - Ignatius and the Princess III 整数拆分问题

B - Ignatius and the Princess III Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I...
  • tianyuhang123
  • tianyuhang123
  • 2016-11-01 21:02:20
  • 384

经典好题!杭电OJ--Ignatius and the Princess I

Ignatius and the Princess I Problem Description The Princess has been abducted by the BEelzebu...
  • lishuhuakai
  • lishuhuakai
  • 2012-10-05 14:54:57
  • 3569

HDU 1026 Ignatius and the Princess I (BFS)

Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J...
  • liangzhaoyang1
  • liangzhaoyang1
  • 2016-05-28 16:04:35
  • 571

HDOJ Ignatius and the Princess III

Ignatius and the Princess III http://acm.hdu.edu.cn/showproblem.php?pid=1028 Time Limit: 2000/1000...
  • aihahaheihei
  • aihahaheihei
  • 2011-09-16 22:30:06
  • 1025

HDU1028 Ignatius and the Princess III(java)

HDU1028 Ignatius and the Princess III java
  • sxd8700
  • sxd8700
  • 2015-09-30 18:08:20
  • 301

hdu 1028 Ignatius and the Princess III(动态规划)

Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K...
  • zjw6463
  • zjw6463
  • 2016-03-15 15:17:27
  • 140
收藏助手
不良信息举报
您举报文章:hdu 1028 Ignatius and the Princess III(母函数)
举报原因:
原因补充:

(最多只允许输入30个字)