HDU1165: Eddy's research II(递推)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1165
果断不擅长找规律啊,做这种题静不下心来。
Ackermann function can be defined recursively as follows:
递推如上图,
0<m<=3,0<=n<=1000000,,当m==3时,n>=0&&n<=24.
首先发现a(0,i)=i+1;
另外n==0时,a(1,0)=a(0,1)=2;
当m==1,n>0时,a(1,n)=a(0,a(1,n-1)=a(1,n-1)+1;
有上式找到当m==1时的递推公式,a(1,i)=a(1,i-1)+1;(其中a(1,0)=2);
所以a(1,i)=i+2;
同理,当m==2,n>0时,a(2,n)=a(1,a(2,n-1))=a(2,n-1)+2;(其中a(2,0)=a(1,1)=3)
所以a(2,i)=2*i+3;
所以a(3,i)=a(2,a(3,i-1))=2*a(3,i-1))+3;
由此可以解出结果。
代码如下:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define inf 0x3f3f3f3f
using namespace std;
int dp[][],n,m;
int main()
{
for(int i=;i<=;i++)
dp[][i]=i+;
dp[][]=;
for(int i=;i<=;i++)
dp[][i]=i+;
dp[][]=;
for(int i=;i<=;i++)
{
dp[][i]=dp[][i-]+;//2*i+3
}
dp[][]=;
for(int i=;i<=;i++)
{
dp[][i]=*(dp[][i-])+;
}
while(scanf("%d%d",&n,&m)!=EOF)
{
printf("%d\n",dp[n][m]);
}
return ;
}
HDU1165: Eddy's research II(递推)的更多相关文章
- HDU 1165 Eddy's research II(给出递归公式,然后找规律)
- Eddy's research II Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1165 Eddy's research II (找规律)
题意:给定一个表达式,然后让你求表达式的值. 析:多写几个就会发现规律. 代码如下: #pragma comment(linker, "/STACK:1024000000,102400000 ...
- HDU 1165 Eddy's research II
题意:已知,求A(m, n). 分析:根据样例模拟一下过程就可以找出递推关系. #include<cstdio> #include<cstring> #include<c ...
- 动态规划入门——Eddy's research II
转载请注明出处:http://blog.csdn.net/a1dark 分析:找规律 #include<stdio.h> int main(){ int m,n; while(scanf( ...
- HDUOJ----1165Eddy's research II
Eddy's research II Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- hdu 1165 Eddy's research II(数学题,递推)
// Eddy 继续 Problem Description As is known, Ackermann function plays an important role in the sphere ...
- [LeetCode] 递推思想的美妙 Best Time to Buy and Sell Stock I, II, III O(n) 解法
题记:在求最大最小值的类似题目中,递推思想的奇妙之处,在于递推过程也就是比较求值的过程,从而做到一次遍历得到结果. LeetCode 上面的这三道题最能展现递推思想的美丽之处了. 题1 Best Ti ...
- Eddy's AC难题--hdu2200(递推)
Problem Description Eddy是个ACMer,他不仅喜欢做ACM题,而且对于Ranklist中每个人的ac数量也有一定的研究,他在无聊时经常在纸上把Ranklist上每个人的ac题目 ...
- Leetcode 119 Pascal's Triangle II 数论递推
杨辉三角,这次要输出第rowIndex行 用滚动数组t进行递推 t[(i+1)%2][j] = t[i%2][j] + t[i%2][j - 1]; class Solution { public: ...
随机推荐
- spring junit 部署两套测试方案
第一套方案: 1.初始化application:使用@ContextConfigurationr的classpath属性,如 @ContextConfiguration(locations = { & ...
- python学习笔记1--python简介
Python翻译中文是蟒蛇.发明人guido喜欢蟒蛇马戏团,故起名python. python发展简史: --CNRI时期.CNRI资助Python发展的重要单位,python1.5版之前的成果大部分 ...
- TP 框架 ajax[利用异步提交表单]
//[] $(function () { $("#send-btn" ).click(function (){ //接受表单的值 var username=$('input[nam ...
- (转载)【C#4.0】dynamic和var及object
dynamic a = 10;a = a + 10;Console.WriteLine(a.GetType()); 此段代码会输出 System.Int32,第二行不需要类型转换,因为在运行时识别类型 ...
- 【BZOJ】2102: [Usaco2010 Dec]The Trough Game(暴力)
http://www.lydsy.com/JudgeOnline/problem.php?id=2102 直接枚举所有情况......然后判断是否可行.. #include <cstdio> ...
- 【BZOJ】3404: [Usaco2009 Open]Cow Digit Game又见数字游戏(博弈论)
http://www.lydsy.com/JudgeOnline/problem.php?id=3404 写挫好几次.... 裸的博弈论即可.. #include <cstdio> #in ...
- redis Could not connect to Redis at 127.0.0.1:6379: Connection refused 问题解决
1.启动redis 客户端 redis-cli 报错 redis Could not connect to Redis at 127.0.0.1:6379: Connection refused 是因 ...
- Setting up PhoneGap on Ubuntu for Android app development
This is just some notes I made, mostly taken from http://docs.phonegap.com/en/3.0.0/guide_overview_i ...
- @RequestMapping 注解
@RequestMapping 注解开发者需要在控制器内部为每一个请求动作开发相应的处理方法.org.springframework.web.bind.annotation.RequestMappin ...
- ios 时间解析 差8个小时
啥问题也有:小程序中web开发工具里显示时间正常,ios上显示的查8小时 原因: 使用 NSDate *date = [NSDate date]; 获取的时间是标注的UTC时间,和北京时间相差8小时. ...