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


    - 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
    ",slove(m,n));
        }
        return 0;
    }
  • 相关阅读:
    存储过程参数传递
    iCkeck插件
    单点登录
    SQL数据库默认实例与命名实例的区别
    IE浏览器重复提交ajax请求有缓存
    IE里Iframe的Cookie问题解决办法总结
    微信公众服务号开发
    解析url参数含有特殊字符的情况
    使用客户端控件展示增删改查操作
    修改网站web.config后出现奇怪问题找不到网页
  • 原文地址:https://www.cnblogs.com/yinbiao/p/9445188.html
Copyright © 2020-2023  润新知