hdu 1165 Eddy's research II

简介: hdu 1165 Eddy's research II

Eddy's research II

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6240    Accepted Submission(s): 2217


 

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:


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

 

一开始读完题想到的是直接递归,但发现这样肯定会超时,想试试递推,发现有点麻烦,然后打表找规律,发现规律如下:

m=0 时                  A(m,n)=n+1

m>0&&n==0时     A(m,n)=2

m=1&&n>0时       A(m,n)=n+2

m=2&&n>0时       A(m,n)=2*(n+1)+1

m=3&&n>0时       符合以下递推公式

A[0]=13;  A[i]=A[i-1]*2+3;

 

 

 

AC代码如下:

#include<stdio.h>
/*
int A(int m,int n)
{
if(m==0) return n+1;
if(m>0&&n==0) return A(m-1,1);
if(m>0&&n>0) return A(m-1,A(m,n-1));
}
*/
int main()
{
__int64 n,m,i,A[25];
A[0]=13;
for(i=1;i<25;i++) A[i]=A[i-1]*2+3;
while(scanf("%I64d %I64d",&m,&n)!=EOF)
{
if(m==0) printf("%I64d\n",n+1);
if(m>0&&n==0) printf("2\n");
if(m>0&&n>0)
{
if(m==1) printf("%I64d\n",n+2);
if(m==2) printf("%I64d\n",2*(n+1)+1);
if(m==3) printf("%I64d\n",A[n-1]);
}
//    printf("%d\n",A(m,n));
}
return 0;
}
目录
相关文章
|
存储 应用服务中间件 测试技术
Elasticsearch Data Stream 数据流使用
Elasticsearch Data Stream 数据流使用
641 0
|
消息中间件 关系型数据库 MySQL
分布式事物-全面详解(学习总结---从入门到深化)
分布式事物-全面详解(学习总结---从入门到深化)
2274 0
|
3月前
|
缓存 API 开发工具
企业级大模型落地指南:Qwen3.8‑Max/Flash/Omni 能力拆解,RAG 知识库、微调、智能体开发与 API 调用全流程
目前生成式AI已经从简单问答对话,进化为可以处理超长文档、图文音视频混合输入、自主拆解目标完成多步骤业务的通用智能底座。通义千问Qwen3.8完整家族形成了分层能力矩阵,覆盖旗舰推理、均衡通用、高速高吞吐、原生全模态视听、专项编程多类基座,既可以普通用户网页端直接交互体验,也可以通过百炼平台API集成进业务系统,同时开放开源权重,支持本地私有化部署,覆盖个人创作者、独立开发者、中小企业、大型政企的差异化诉求。
544 0
|
安全 程序员 编译器
【C/C++ 泛型编程 进阶篇 Type traits 】C++类型特征探究:编译时类型判断的艺术
【C/C++ 泛型编程 进阶篇 Type traits 】C++类型特征探究:编译时类型判断的艺术
1454 1
|
SQL 安全 Shell
扫描神器:Netsparker 保姆级教程(附链接)
漏洞扫描神器:Netsparker 保姆级教程(附链接)
扫描神器:Netsparker 保姆级教程(附链接)
|
Perl 容器 Kubernetes
从零开始入门 | Kubernetes 中的服务发现与负载均衡
作者 | 阿里巴巴技术专家  溪恒 一、需求来源 为什么需要服务发现 在 K8s 集群里面会通过 pod 去部署应用,与传统的应用部署不同,传统应用部署在给定的机器上面去部署,我们知道怎么去调用别的机器的 IP 地址。
|
监控 负载均衡 架构师
架构师养成手册:性能指数
本文介绍了架构师关注的性能指标,包括QPS(每秒查询率)、TPS(每秒事务处理数)、RT(响应时间)、UV(独立访客数)、并发数和线程数。QPS和TPS衡量系统处理能力,RT影响用户体验,UV评估网站流量,高并发和线程管理关乎系统稳定性和效率。理解并优化这些指标有助于构建高性能系统。
706 8
|
缓存 算法 NoSQL
短信验证码登录接口,如何防止恶意攻击
该文讨论了移动应用中常见的手机短信验证码登录(短验登录)的安全设计。后端通常需要提供获取短信验证码和手机短验登录两个API。为了增强机短验登录API的安全性,提出了几种无需依赖Redis等存储介质的方案:1)使用数字签名确保请求合法性;2)基于时间戳的验证,允许在一定时间范围内有效;3)应用TOTP算法生成动态码进行验证;4)利用JWTToken进行身份验证并设置有效期。文章强调了创新思考在解决安全问题中的重要性,并鼓励读者分享更多方案。
1645 1