码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 1165 Eddy's research II(给出递归公式,然后找规律)

时间:2018-08-08 19:53:06      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:awl   import   ==   ret   递归   应该   form   limit   term   

- Eddy‘s research II
Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
Submit Status

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
 
分析:
告诉你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;
}

 

HDU 1165 Eddy's research II(给出递归公式,然后找规律)

标签:awl   import   ==   ret   递归   应该   form   limit   term   

原文地址:https://www.cnblogs.com/yinbiao/p/9445188.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!