博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 1028 Ignatius and the Princess III(母函数)
阅读量:5050 次
发布时间:2019-06-12

本文共 2002 字,大约阅读时间需要 6 分钟。

Ignatius and the Princess III

                Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

                       Total Submission(s): 9408    Accepted Submission(s): 6642

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
 
题目链接:
 
题目分析:题目要求的是整数的拆分方案个数,用母函数处理。
 
母函数详解链接:
 
1 #include 
2 3 int N; 4 const int MAX_NUM = 125; 5 int solNum[MAX_NUM]; 6 int temp[MAX_NUM]; 7 8 void InitGenerFun() 9 {10 for(int i = 0; i < MAX_NUM; i++)11 {12 solNum[i] = 1;13 temp[i] = 0;14 }15 for(int i = 2; i < MAX_NUM; i++)16 {17 for(int j = 0; j < MAX_NUM; j++)18 {19 for(int k = 0; k+j < MAX_NUM; k+=i)20 {21 temp[k+j] += solNum[j];22 }23 }24 for(int k = 0; k < MAX_NUM; k++)25 {26 solNum[k] = temp[k];27 temp[k] = 0;28 }29 }30 }31 32 int main()33 {34 InitGenerFun();35 36 while(scanf("%d", &N) != EOF)37 {38 printf("%d\n", solNum[N]);39 }40 41 return 0;42 }

 

转载于:https://www.cnblogs.com/Dreamcaihao/archive/2013/05/29/3107204.html

你可能感兴趣的文章
浅谈animation里的forwards
查看>>
事件的节流(throttle)与防抖(debounce)
查看>>
07_ddms透视图介绍
查看>>
python初步学习-python模块之 logging
查看>>
Molas——.NET依赖分离框架
查看>>
静态页面传值
查看>>
智能手持终端方案
查看>>
基于visual Studio2013解决C语言竞赛题之0408素数
查看>>
Harbor-企业级Registry服务器使用(图解)
查看>>
新建的亚马逊云服务器EC2 ping 不通 解决方案
查看>>
一 数据的概括性度量
查看>>
Spring boot(一) 入门
查看>>
使用SMACK堆栈进行快速数据分析(转载)
查看>>
水平垂直居中的那些事儿
查看>>
Slickflow.NET 开源工作流引擎基础介绍(二) -- 引擎组件和业务系统的集成
查看>>
【iOS7开发笔记】tableview之Cell的重用原理
查看>>
什么是ODBC和JDBC?
查看>>
蓝桥杯- 入门训练 Fibonacci数列
查看>>
EnableEventValidation错误原因分析以及解决办法
查看>>
Java编程练习(四)——集合框架应用
查看>>