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. WKWebView无法(通过URL schemes)跳转到其他App

    Custom scheme URL 在WKWebView中默认是不支持的 (但Safari可以). 我们可以通过NSError来进行一些处理从而使得程序可以正常跳转: func webView(web ...

  2. weewwe

    http://blog.csdn.net/u013073524/article/details/25912891

  3. html-----016---HTTP 状态消息

    HTTP 状态消息 当浏览器从 web 服务器请求服务时,可能会发生错误. 从而有可能会返回下面的一系列状态消息: 1xx: 信息 消息: 描述: 100 Continue 服务器仅接收到部分请求,但 ...

  4. 当传递具有已修改行的 DataRow 集合时,更新要求有效的 UpdateCommand问题解决

    1.目前看主要因为两种,第一种是select语句没有包含主键列,select *  就可以解决.或 select 主键列 这里的主键是指的primary key而不是unique key 2.最重要的 ...

  5. java新手笔记23 异常

    1.import package com.yfs.javase; import java.util.Scanner; //import java.lang.String;//默认导入 public c ...

  6. ERROR 1045 (28000): Access denied for user 'root'@'localhost'

    # /etc/init.d/mysql stop# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &# mysq ...

  7. Codevs 4560 NOIP2015 D2T2 子串

    > 4560 NOIP2015 D2T2 子串 时间限制: 1 s 空间限制: 128000 KB 题目等级:黄金 Gold 题目描述 Description 有两个仅包含小写英文字母的字符串A ...

  8. discuz xplus 模板 没解析的问题

    <?xxx?> 模板中用得是短标签,没加php, 在php.ini中,把 open_short_tag = On ; 打开即可!浪费一上午的时间

  9. Debian vim没有颜色的解决办法

    最近在研究Linux kali 3.12-kali1-amd64  Debian 3.12.6-2kali1  x86_64 GNU/Linux Debian的内核 发现vim竟然没有颜色,root或 ...

  10. winform模拟鼠标按键

    今天朋友说被他们公司的学习网站恶心到了,下班后要他看学习资料,看完点下一页,而且一页必须停留多少时间才能点击下一页,想不看都不行,于是晚上我突发奇想要给他做一个模拟鼠标按键的程序,可以让鼠标定时间隔触 ...