HDU 1165 Eddy's research II(给出递归公式,然后找规律)
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:
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).
Ackermann function can be defined recursively as follows:

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.
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
分析:
告诉你m<=3,所以我们应该往这方面靠
看看m不同,是不是有不同的n的公式
纯粹找规律
。。。。。
根据递推公式
记忆化搜一下
打印m不同值 n相同值的结果出来
然后找规律。。。。
code:
#include <iostream> #include <cstdio> #include<stdio.h> #include<algorithm> #include<cstring> #include<math.h> #include<memory> #include<queue> #include<vector> using namespace std; int f(int n) { int s=1; for(int i=1;i<=n;i++) { s=s*2; } return s; } int slove(int m,int n) { if(m==0) return n+1; if(m==1) return n+2; if(m==2) return 2*n+3; if(m==3) return f(n+3)-3; } int main() { int n,m; while(~scanf("%d %d",&m,&n)) { printf("%d\n",slove(m,n)); } return 0; }
心之所向,素履以往
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南