Ignatius and the Princess III

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

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
 
思路:一开始拿到这个题目以为是找规律,有递推关系什么的,最后找了好长时间没找到规律,上网查了一下才发现是用母函数做,就是把数的加法和指数乘法的幂的加法联系起来,母函数:G(x)=(1+x+x^2+x^3+x^4+.....)*(1+x^2+x^4+x^6+....)*(1+x^3+x^6+x^9+....)*... ,x^n的系数就是n的拆分方案数!其实这个不难理解,因为x^n的系数是多少就表明有多少个x^n相加得来,换句话说就是有多少种x的幂之和的拼凑方案,即本题所求。
 
#include<stdio.h>
int a[],b[]; // a[i]表示x^i的系数,为临时值,b[i]表示x^i的系数,为最终值;
int
main()
{

int
i,j,k,n;
for
(i =;i <=;i ++)
{

a[i] =;
b[i] =;
}

for
(i =;i <=;i ++)
{

for
(j =;j <=;j ++)
{

for
(k =;k+j <=; k += i)
a[k+j] += b[j]; //因为x^(k+j)是从x^j得来的,故它的系数应该在原有系数的数值的基础上加上x^j                 
                      的系数(这是关键的重点!!!这就是为什么我们要用两个数组的目的)
}

for
(j =;j <=;j ++)
{

b[j] = a[j];
a[j] =;
}
}

while
(~scanf("%d",&n))
printf("%d\n",b[n]);
  return 0;
}

Ignatius and the Princess III的更多相关文章

  1. 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 ...

  2. 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 ...

  3. hdu 1028 Ignatius and the Princess III 简单dp

    题目链接:hdu 1028 Ignatius and the Princess III 题意:对于给定的n,问有多少种组成方式 思路:dp[i][j],i表示要求的数,j表示组成i的最大值,最后答案是 ...

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

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

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

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

  6. Ignatius and the Princess III --undo

    Ignatius and the Princess III Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (J ...

  7. Ignatius and the Princess III(母函数)

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

  8. 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 ...

  9. HDU 1028 整数拆分问题 Ignatius and the Princess III

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

随机推荐

  1. UIImageView的图片拉伸

    iOS 8:UIView Stretching设置 使用小图片当变长输入框或类似QQ聊天文字背景效果时,需要拉伸图片.UIImage提供了三个可完成此任务的方法: resizableImageWith ...

  2. O-C相关06:self和super关键字介绍——self关键字

    self关键字介绍 1.self和super OC 版权声明:本文为博主原创文章,未经博主允许不得转载. posted @ 2015-08-04 12:46 王刚韧(wanghy_iOS) 阅读(.. ...

  3. requirejs下载与配置

    写在开始: requirejs有中文版api文档,可以访问http://www.requirejs.cn/home.html 下载requirejs 访问http://www.requirejs.cn ...

  4. VS中使用sqlite静态连接

    说明 最近写的文章有些多,懒得打字了,就直接上文章.这里说明一下,我说的是VS,不是指定的哪一个VS版本.先下载官方的源文件:sqlite-amalgamation-3071502.zip 下载下来的 ...

  5. Nginx(一)初始环境的安装(php5.3+mysql5.1+fastcgi…)

    关参考资源http://www.lnmp.org/index.html \\LNMP一键安装包http://www.howtocn.org/nginx \\Nginx模块参考手册中文版http://b ...

  6. 给定任意一个字符串,使用 for in 语句来统计字符出现的个数

    //找出字符串中的数字 var str = 'haj123sdk54hask33dkhalsd879'; /*function findNum(str){ var arr = []; var tmp ...

  7. 初用jquery

    ---恢复内容开始--- 这两天在顶顶大人的指导下,利用jquery框架做了一个动态切换的小页面.最终效果图: 这么萌萌哒的图片让我觉得一直在测试也没那么累.实现功能如下: 1.打开页面时,自动切换, ...

  8. 移动web问题小结

    Meta标签: <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalab ...

  9. angularjs制作的iframe后台管理页切换页面

    <code> <!DOCTYPE html><html lang="zh" ng-app><head> <meta chars ...

  10. node 通过mongoose实现 mongodb的增删改

    node 通过mongoose实现 mongodb的增删改   新建文件test.js 内容如下:   var mongoose = require('mongoose') , Schema = mo ...