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;
}
目录
相关文章
|
3月前
|
Java
hdu 1164 Eddy's research I
hdu 1164 Eddy's research I
18 0
|
6月前
|
人工智能 Java
hdu 1165 Eddy's research II
hdu 1165 Eddy's research II
32 0
hdu 1165 Eddy's research II
|
12月前
The Preliminary Contest for ICPC China Nanchang National Invitational M题 Subsequence
The Preliminary Contest for ICPC China Nanchang National Invitational M题 Subsequence
51 0
|
12月前
The Preliminary Contest for ICPC China Nanchang National Invitational H题 Coloring Game
The Preliminary Contest for ICPC China Nanchang National Invitational H题 Coloring Game
69 0
|
12月前
|
机器学习/深度学习 人工智能
The Preliminary Contest for ICPC China Nanchang National Invitational K题 MORE XOR
The Preliminary Contest for ICPC China Nanchang National Invitational K题 MORE XOR
53 0
|
人工智能
upc 2021秋组队训练赛第三场 2020 Rocky Mountain Regional Contest
upc 2021秋组队训练赛第三场 2020 Rocky Mountain Regional Contest
76 0
upc2021秋组队训练赛第一场 ICPC North Central NA Contest 2020
upc2021秋组队训练赛第一场 ICPC North Central NA Contest 2020
70 0
upc2021秋组队训练赛第一场 ICPC North Central NA Contest 2020
|
机器学习/深度学习 BI
2020-2021 ACM-ICPC, Asia Seoul Regional Contest L. Two Buildings (决策单调性 分治)
2020-2021 ACM-ICPC, Asia Seoul Regional Contest L. Two Buildings (决策单调性 分治)
94 0
2020-2021 ACM-ICPC, Asia Seoul Regional Contest L. Two Buildings (决策单调性 分治)
AtCoder Beginner Contest 133 E - Virus Tree 2(组合数学)
AtCoder Beginner Contest 133 E - Virus Tree 2(组合数学)
77 0