Ignatius and the Princess III

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

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

C/C++:

 #include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <string>
#include <cstdio>
#include <cstring>
#include <climits>
#include <iostream>
#include <algorithm>
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
const int MAX = 2e2 + ; int n, ans[MAX], temp[MAX]; void calc()
{
for (int i = ; i <= ; ++ i)
ans[i] = , temp[i] = ;
for (int i = ; i <= ; ++ i)
{
for (int j = ; j <= ; ++ j)
for (int k = ; j + k <= ; k += i)
temp[j + k] += ans[j];
for (int j = ; j <= ; ++ j)
ans[j] = temp[j], temp[j] = ;
}
} int main()
{
calc();
while (~scanf("%d", &n))
printf("%d\n", ans[n]);
return ;
}

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

  1. hdu 1028 Ignatius and the Princess III 母函数

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

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

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

  3. 1028:Ignatius and the Princess III

    本题应该有两种方法: 1.母函数法 2.递推法 母函数不了解,待充分了解之后,再进行补充! 这里为递推实现的方法: 思路: 定义:n为要拆分的整数: k为拆分的项数: f[n][k]代表 n的整数拆分 ...

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

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

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

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

  7. Ignatius and the Princess III HDU - 1028 || 整数拆分,母函数

    Ignatius and the Princess III HDU - 1028 整数划分问题 假的dp(复杂度不对) #include<cstdio> #include<cstri ...

  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. Python之反射机制

    什么是反射? 1.有时我们要访问某个变量或是方法时并不知道到底有没有这个变量或方法,所以就要做些判断.判断是否存在字符串对应的变量及方法.2.我们知道访问变量时是不能加引号的,否则会被当成字符串处理. ...

  2. PHP 插入排序 -- 直接插入排序

    1)直接插入序 -- Straight Insertion Sort 时间复杂度 :O(n^2) 适用条件: 适合记录数不多的情况 1 <?php 2 $a = [0 =>3,4,5,1, ...

  3. luoguP2144 [FJOI2007]轮状病毒

    题目描述 求 nnn 个点的生成树个数. Solution 2144\text{Solution 2144}Solution 2144 打表得 1=125=5×1216=4245=5×32121=11 ...

  4. python学习-面向对象(六)

    1.类中的实例方法 self参数最大的作用是引用当前方法的调用者 类调用实例方法,python不会位为一个参数绑定调用者(因为实例方法的调用者应该是对象,而此时是类) 2.类方法与静态方法

  5. 2019.10.26 CSP%您赛第三场

    \(CSP\)凉心模拟^_^ --题源\(lqx.lhc\)等各位蒟蒻 题目名称 比赛 传递消息 开关灯 源文件名 \(competition.cpp\) \(message.cpp\) \(ligh ...

  6. vue-cli3 搭建 vue 项目

    vue-cli3 搭建 vue 项目 项目是在mac的环境下配置的 win的同学请移步[https://www.cnblogs.com/zhaomeizi/p/8483597.html] 安装 nod ...

  7. Jedis运用scan删除正则匹配的key

    jedis运用scan删除正则匹配的key  我们都知道用keys *进行查询key的时候会进行堵塞,导致redis整体不可用,而使用scan命令则不会.   RedisServiceImpl中sca ...

  8. Linux常用命令-不定时记录

    文件移动命令 命令格式:mv [-fiv] source destination 参数说明:-f:force,强制直接移动而不询问-i:若目标文件(destination)已经存在,就会询问是否覆盖- ...

  9. 面试题-javascript-面向对象编程

    笔者在某次笔试中遇到这个题:印象很深. function ClassA() { var value=4; this.getValue= function() { return value; } thi ...

  10. day3,用户交互,input的应用

    1.与用户交互 输入:input() python2.x版本 input后面家的东西要声明输入的类型       >>> input(">>:")   ...