Ignatius and the Princess III

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

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
 
Author
Ignatius.L
 
Recommend
We have carefully selected several similar problems for you:  1171 1085 1398 2152 1709 
 
问整数n有多少种拆分可能,那也就是求x^n的系数
所以我们直接用母函数求x^n的系数就行
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iterator>
#include <iostream>
#include <algorithm>
#define debug(a) cout << #a << " " << a << endl
using namespace std;
const int maxn = 2*1e2 + 10;
const int mod = 10000;
typedef long long ll;
int main() {
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
ll n;
while( cin >> n ) {
ll a[maxn], b[maxn];
for( ll i = 0; i <= n; i ++ ) {
a[i] = 1, b[i] = 0;
}
for( ll i = 2; i <= n; i ++ ) { //最低是从2开始划分
for( ll j = 0; j <= n; j ++ ) {
for( ll k = 0; k*i+j <= n; k ++ ) {
b[k*i+j] += a[j];
}
}
for( ll j = 0; j <= n; j ++ ) {
a[j] = b[j], b[j] = 0;
}
}
cout << a[n] << endl;
}
return 0;
}

  

hdu 1028 Ignatius and the Princess III 母函数的更多相关文章

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

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

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

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

  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. hdu 1028 Ignatius and the Princess III (n的划分)

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

  6. HDU 1028 Ignatius and the Princess III (生成函数/母函数)

    题目链接:HDU 1028 Problem Description "Well, it seems the first problem is too easy. I will let you ...

  7. HDU 1028 Ignatius and the Princess III (递归,dp)

    以下引用部分全都来自:http://blog.csdn.net/ice_crazy/article/details/7478802  Ice—Crazy的专栏 分析: HDU 1028 摘: 本题的意 ...

  8. HDU 1028 Ignatius and the Princess III (动态规划)

    题目链接:HDU 1028 Problem Description "Well, it seems the first problem is too easy. I will let you ...

  9. HDU 1028 Ignatius and the Princess III:dp or 母函数

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1028 题意: 给你一个正整数n,将n拆分成若干个正整数之和,问你有多少种方案. 注:"4 = ...

随机推荐

  1. 设置Myeclipse的jvm内存参数

    Myeclipse经常会遇到内存溢出和Gc开销过大的情况,这时候就需要修改Myeclipse的Jvm内存参数 修改如下:(使用Extjs做公司大项目时候,不要让项目Builders的Javascrip ...

  2. linux集群实施与部署-----Nginx

    ( 1 ) 配置基本环境 //安装虚拟工具 #cd /media/VMware\ Tools/ #cp VMwareTools--.tar.gz/tmp/ #cd /tmp/ #tar-xvzf VM ...

  3. 【原创】HashMap复习精讲

    引言 由于近期忙着搬家,又偷懒了几个礼拜! 其实我很早以前就想写一篇关于HashMap的面试专题.对于JAVA求职者来说,HashMap可谓是集合类的重中之重,甚至你在复习的时候,其他集合类都不用看, ...

  4. 第四章 文件的基本管理和XFS文件系统备份恢复 随堂笔记

    第四章 文件的基本管理和XFS文件系统备份恢复 本节所讲内容: 4.1 Linux系统目录结构和相对/绝对路径. 4.2 创建/复制/删除文件,rm -rf / 意外事故 4.3 查看文件内容的命令 ...

  5. 把Jar包加入windows系统服务

    之前在服务器上不一个Java服务时候,总是开着一堆黑框框,非常不雅,重点是极其容易误关,所以把可执行Jar文件加入Windows系统服务,看起来是个非常不错的选择!(实际上也确实是非常不错的选择) ! ...

  6. java多线程基础(二)--sleep(),wait,()yield()和join()方法

    1.sleep()方法 在指定时间内让当前正在执行的线程暂停执行,但不会释放“锁标志”.不推荐使用. sleep()使当前线程进入阻塞状态,在指定时间内不会执行. 2.wait()方法 在其他线程调用 ...

  7. 7.15 迭代器 for循环的本质 生成器

    迭代器 迭代:更新换代的过程,每次的迭代都必须基于上一次的结果 迭代器:迭代取值的工具 作用 迭代器提供了一种不依赖于索引取值的方式 根据以上对于迭代的描述,如果只是简单的重复,不算迭代,如下: n ...

  8. R 实用命令 1

    Quit and restart a clean R session from within R? If you're in RStudio: command/ctrl + shift + F10 . ...

  9. HBase的高可用(HA)

    在公司写文档时候查到的一些资料,感觉对自己很有帮助,现在整理如下: 介绍 HBase是一个高可靠性.高性能.列存储.可伸缩.实时读写的分布式数据库系统,基于列的存储模式适合于存储非结构化数据. 适用场 ...

  10. Android老司机搬砖小技巧

    作为一名Android世界的搬运工,每天搬砖已经够苦够累了,走在坑坑洼洼的道路一不小心就掉坑里了. SDK常用工具类 Android SDK中本身就拥有很多轮子,熟悉这些轮子,可以提高我们的搬砖效率. ...