题目链接:HDU 1028

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

Solution

题意

给定 \(n\),求 \(n\) 的划分数。

思路

普通母函数。母函数 \(G(x) = (1+x+x^2+...)(1+x^2+x^4+...)(1+x^3+x^6+...)...\)。

\((1+x+x^2+...)=(x^{0\times1}+x^{1\times1}+x^{2\times1}+...)\) 代表不用数字 \(1\),用一次数字 \(1\),用两次数字 \(1\)……

动态规划的版本见这里

Code

#include <bits/stdc++.h>
using namespace std;
const int maxn = 200; int c1[maxn], c2[maxn]; void init() {
for(int i = 0; i < maxn; ++i) {
c1[i] = 1;
c2[i] = 0;
}
for(int i = 2; i < maxn; ++i) {
for(int j = 0; j < maxn; ++j) {
for(int k = 0; k + j < maxn; k += i) {
c2[k + j] += c1[j];
}
}
for(int j = 0; j < maxn; ++j) {
c1[j] = c2[j];
c2[j] = 0;
}
}
} int main() {
init();
int n;
while(~scanf("%d", &n)) {
printf("%d\n", c1[n]);
}
return 0;
}

HDU 1028 Ignatius and the Princess III (生成函数/母函数)的更多相关文章

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

  2. 题解报告:hdu 1028 Ignatius and the Princess III(母函数or计数DP)

    Problem Description "Well, it seems the first problem is too easy. I will let you know how fool ...

  3. hdu 1028 Ignatius and the Princess III(母函数入门+模板)

    Description "Well, it seems the first problem is too easy. I will let you know how foolish you ...

  4. HDU 1028 Ignatius and the Princess III(母函数整数拆分)

    链接:传送门 题意:一个数n有多少种拆分方法 思路:典型母函数在整数拆分上的应用 /********************************************************** ...

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

    题意: N=a[1]+a[2]+a[3]+...+a[m];  a[i]>0,1<=m<=N; 例如: 4 = 4;  4 = 3 + 1;  4 = 2 + 2;  4 = 2 + ...

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

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

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

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

  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. CSS选择器,优先级的总结

    CSS选择器 css选择器种类 基本选择器: 通配符选择器 * id选择器 #id 类选择器 .className 元素选择器 E 元素后代选择器  E F 子元素选择器 E > F 相邻兄弟元 ...

  2. docker pull理解误区

    docker run 命令 如果local image中有对应 镜像+tag 不会从新拉取镜像 docker pull 会进行拉取 先进行镜像更改 [root@master01 ~]# docker ...

  3. Mybatis-技术专区-中的条件查询createCriteria example里面的条件

    之前用Mybatis框架反向的实体,还有实体里面的Example,之前只是知道Example里面放的是条件查询的方法,可以一直不知道怎么用,到今天才开始知道怎么简单的用. 在我们前台查询的时候会有许多 ...

  4. javaScript--基础 选择结构

    2.短路现象--扩展 当 true 遇到 ||  ,  true || 表达式不执行,  右侧的表达式不执行 当false 遇到 && ,  false && 表达式不 ...

  5. 录制rtsp音视频

    1.使用ffmpeg来录制rtsp视频 视频 ffmpeg -y -i rtsp://172.16.23.66:554/h264major -vcodec copy -f mp4 record.mp4 ...

  6. shell变量的声明和使用

  7. how to pass variable from shell script to sqlplus

    script sqlplus ${ORA_USR}/${ORA_PASS}@${ORA_DB} @${PARM}/TEST $new_usr $model_usr $new_pwd parm of s ...

  8. usb server新产品(旧老板设备)-给自己一个学习硬件的动力

  9. Kotlin——关于字符串(String)常用操作汇总

    在前面讲解Kotlin数据类型的时候,提到了字符串类型,当然关于其定义在前面的章节中已经讲解过了.对Kotlin中的数据类型不清楚的同学.请参考Kotlin——初级篇(三):数据类型详解这篇文章. 在 ...

  10. HTML5 表单提交实例

    html <!DOCTYPE html> <html> <head> <title>表单</title> <meta charset= ...