POJ 1579
来源:互联网 发布:青岛软件研发 编辑:程序博客网 时间:2024/06/05 07:07
Description
We all love recursion! Don't we?
Consider a three-parameter recursive function w(a, b, c):
if a <= 0 or b <= 0 or c <= 0, then w(a, b, c) returns:
1
if a > 20 or b > 20 or c > 20, then w(a, b, c) returns:
w(20, 20, 20)
if a < b and b < c, then w(a, b, c) returns:
w(a, b, c-1) + w(a, b-1, c-1) - w(a, b-1, c)
otherwise it returns:
w(a-1, b, c) + w(a-1, b-1, c) + w(a-1, b, c-1) - w(a-1, b-1, c-1)
This is an easy function to implement. The problem is, if implemented directly, for moderate values of a, b and c (for example, a = 15, b = 15, c = 15), the program takes hours to run because of the massive recursion.
Consider a three-parameter recursive function w(a, b, c):
if a <= 0 or b <= 0 or c <= 0, then w(a, b, c) returns:
1
if a > 20 or b > 20 or c > 20, then w(a, b, c) returns:
w(20, 20, 20)
if a < b and b < c, then w(a, b, c) returns:
w(a, b, c-1) + w(a, b-1, c-1) - w(a, b-1, c)
otherwise it returns:
w(a-1, b, c) + w(a-1, b-1, c) + w(a-1, b, c-1) - w(a-1, b-1, c-1)
This is an easy function to implement. The problem is, if implemented directly, for moderate values of a, b and c (for example, a = 15, b = 15, c = 15), the program takes hours to run because of the massive recursion.
Input
The input for your program will be a series of integer triples, one per line, until the end-of-file flag of -1 -1 -1. Using the above technique, you are to calculate w(a, b, c) efficiently and print the result.
Output
Print the value for w(a,b,c) for each triple.
Sample Input
1 1 12 2 210 4 650 50 50-1 7 18-1 -1 -1
Sample Output
w(1, 1, 1) = 2w(2, 2, 2) = 4w(10, 4, 6) = 523w(50, 50, 50) = 1048576w(-1, 7, 18) = 1
题意:大家爱递归!。说实话我怎么爱递归。简单来讲。根据题目给的要求对一组数字进行递归。常规的dfs会超时,所以进行记忆化搜索。没啥子好说的。
0 0
- POJ 1579
- poj 1579
- POJ 1579
- POJ 1579
- poj 1579
- poj 1579
- POJ 1579
- POJ 1579
- POJ-1579
- POJ 1579
- poj-1579
- poj 1579(递归)
- POJ 1579 记忆递归
- Poj 1579 题解
- POJ 1579 解题报告
- POJ 1579(备忘录算法)
- POJ
- poj
- 杭电2032杨辉三角
- windows 端口
- springMVC之拦截器-HandlerInterceptor
- C# 图形编程 for RadioButton group ,checked & find
- Java中HashTable和HashMap区别
- POJ 1579
- RGB转换成十六进制
- Flash 插件面板 DragonBonesDesignPanel 的绿色安装方法
- 为什么选择 SaaS
- css中定位的问题(position)
- Android 自定义 ViewPager 打造千变万化的图片切换效果
- Intent打开ppt、word、Excel
- 算法导论—排序—插入排序
- 电视游戏大厅现状:“渠道为王”遭遇水土不服