Ignatius and the Princess III

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

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
 

最简单的母函数模板题,用于学习和回顾母函数非常方便,代码也可直接做模板使用

 /*
hdu acm 1028 数字拆分,母函数模板题
by zhh
*/
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cstring> using namespace std;
#define maxx 120
int ans[maxx+],temp[maxx+];
void init()//母函数打表
{
for(int i=;i<=maxx;i++)//初始化第一个式子系数
{
ans[i]=;
temp[i]=;//用于临时保存每次相乘的结果
}
for(int i=;i<=maxx;i++)//循环每一个式子
{
for(int j=;j<=maxx;j++)//循环第一个式子各项
for(int k=;k+j<=maxx;k+=i)//下个式子的各项
temp[k+j]+=ans[j];//结果保存到temp数组中
for(int j=;j<=maxx;j++)//临时保存的值存入ans数组
{
ans[j]=temp[j];
temp[j]=;
}
}
}
int main()
{
init();
int n;
while(scanf("%d",&n)!=EOF)
{
cout<<ans[n]<<endl;
}
return ;
}

hdu acm 1028 数字拆分Ignatius and the Princess III的更多相关文章

  1. ACM学习历程—HDU1028 Ignatius and the Princess III(递推 || 母函数)

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

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

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

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

    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 整数的划分问题(打表或者记忆化搜索)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1028 Ignatius and the Princess III Time Limit: 2000/1 ...

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

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

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

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

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

  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 Sample Ignatius and the Princess III (母函数)

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

随机推荐

  1. centos7搭建samb

    1,smb配置文件 [global] workgroup = WORKGROUP netbios name = LinuxSir05 server string = Linux Samba Serve ...

  2. oracle生成单据号

    --创建单据号存放表 CREATE TABLE BU_TAB( DOC_NUM NUMBER --生成的单据号 ); --单据号 create table cux_doc_num( tab ), -- ...

  3. eclipse- Web-app verson=2.5 调整将Dynamic Web Module3.0降为2.5

    如果提示cannot change version of project facet Dynamic Web Module to 2.5 1.把Dynamic Web Module复选框,勾选去掉,点 ...

  4. js中的一些容易混淆的方法!

    数组的一些方法: 1.join()和split()方法  与之相反的是split()方法:用于把一个字符串分割成字符串数组.  注意返回的数组中不包括separator本身: 提示和注释注释:如果把空 ...

  5. github 添加项目

    下载git安装 ->https://git-scm.com/downloads 新建git目录 在目录下右键选择Git Bash Here 执行 git init 拷贝项目到git目录下 在gi ...

  6. padding和margin的区别

    简单来说,padding就是内边距,margin就是外边距如下图: margin和padding的区别用图表示为:

  7. 問題排查:类型“System.DateTime”的对象无法转换为类型“System.String”

    最近在擴充資料對接工具的功能 經常會遇到這個狀況 當然還有其他同類提示,例如 int/decimal 無法轉 System.String 等等 無獨有偶 這些錯誤幾乎都是在 DataTable 轉換成 ...

  8. 2-4. Using auto with Functions

    在C++14中允许使用type deduction用于函数参数和函数返回值 Return Type Deduction in C++11 #include <iostream> using ...

  9. python文件、数据库读写编码的问题

    读写utf-8文件 fh = open(file_name, 'r', encoding = 'UTF-8') 读写数据库utf-8格式 connect = pymysql.connect(host= ...

  10. NLS_LANG

    NLS_LANG是一个环境变量,用于定义语言,地域以及字符集属性.对于非英语的字符集,NLS_LANG的设置就非常重要. NLS:‘National Language Support (NLS)’ 当 ...