HDU 1165 Eddy's research II
2016-06-15 22:45
447 查看
Eddy's research II
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4141 Accepted Submission(s): 1545
Problem Description
As is known, Ackermann function plays an important role in the sphere of theoretical computer science. However, in the other hand, the dramatic fast increasing pace of the function caused the value of Ackermann function hard to calcuate.
Ackermann function can be defined recursively as follows:
![](http://acm.hdu.edu.cn/data/images/1165-1.jpg)
Now Eddy Gives you two numbers: m and n, your task is to compute the value of A(m,n) .This is so easy problem,If you slove this problem,you will receive a prize(Eddy will invite you to hdu restaurant to have supper).
Input
Each line of the input will have two integers, namely m, n, where 0 < m < =3.
Note that when m<3, n can be any integer less than 1000000, while m=3, the value of n is restricted within 24.
Input is terminated by end of file.
Output
For each value of m,n, print out the value of A(m,n).
Sample Input
1 3
2 4
Sample Output
5
11
Author
eddy
Recommend
JGShining | We have carefully selected several similar problems for you: 1158 1159 1114 1074 1208
思路:直接算,超时了,那就找规律呗。推规律,真麻烦,算着算着把自己算晕了。
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/wronged.gif)
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int a[5][110000],i,j,k,l,m,n; //int dfs(int m,int n)利用这个找出一部分值,便于找规律。 //{ // if(m==0) // return n+1; // if(m>0&&n==0) // return dfs(m-1,1); // if(m>0&&n>0) // return dfs(m-1,dfs(m,n-1)); //} void init() { a[3][0]=5; for(i=0;i<110000;i++) { a[0][i]=i+1; a[1][i]=i+2; a[2][i]=2*i+3; } for(i=1;i<=24;i++) a[3][i]=a[3][i-1]*2+3; } int main() { init(); while(scanf("%d%d",&m,&n)!=EOF) { //printf("%d\n",dfs(m,n)); printf("%d\n",a[m] ); } return 0; }
相关文章推荐
- 浅谈从微观角度看访问网站的过程
- iOS开发教程:Storyboard全解析-第一部分
- Java并发编程一:volatile关键字
- 使用BCP命令管理不同域名间AX数据库拷贝后用户管理
- ASIHTTPRequest的使用——队列请求
- Android SQLite 数据库存储
- IntentFilter与隐式Intent
- Mob ShareSDK的使用
- 毕向东Java视频学习笔记【day01-day07】
- Linkedin卖出好价钱,能给中国企业级市场带来什么启示?
- 在QWidget 窗口上弹出右键菜单
- log4j:WARN Please initialize the log4j system properly
- swift读取plist文件内容用UITableView展示
- kalman 滤波 演示与opencv代码
- JSP中JQuery UI Dialog弹窗使用具体操作
- 网站运营怎么寻找“种子用户”?
- 网站运营怎么寻找“种子用户”?
- 线程操作,比 handler更简单的AsyncTask 使用详解-基础java线程
- 常见进程调度算法
- LLDB命令详解(自用备忘)