zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    tr的最后一个td
    Jquery的parent方法,这里只讲parent方法
    js判断字符串包含字符串的方法 | 标签包含文本
    js中substring和substr的用法
    一个由印度人编写的VC串口类
    VS2010编译Qt5.4.0静态库
    QT5.4关联VS2010,配置VAssistX关联Qt类
    iOS 关于tableView中有多个textField,输入框被遮住的解决方法
    iOS 之URL schemes
    iOS 之改变状态栏颜色
  • 原文地址:https://www.cnblogs.com/yinbiao/p/9445188.html
Copyright © 2011-2022 走看看