zoukankan      html  css  js  c++  java
  • hdu 1165 Eddy's research II(数学题,递推)

    // Eddy 继续

    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
     
    /********************
    看到哦这个题的第一眼感觉像是递推,然后依据那个题目中的公式发现不太好找。就先写了一个递归。打表,然后。恩。找规律……

    打表,这才是真正的打表啊……


    看到这个表,规律就不用我说了吧……

    *************************/

    Code:

    #include <iostream>
    #include <string.h>
    #include <stdio.h>
    using namespace std;
    int num[30];
    int main()
    {
        int i,j,n,m;
        num[0] = 5;
        for(i = 1;i<30;i++)
            num[i] = num[i-1]*2+3;
        while(cin>>m>>n&&m&&n)
        {
            if(m==1)
                printf("%d
    ",n+2);
            if(m==2)
                printf("%d
    ",2*n+3);
            if(m==3)
                printf("%d
    ",num[n]);
        }
        return 0;
    }
    


  • 相关阅读:
    hdu 4324(dfs)
    hdu 2376(求树上任意两点之间距离之和的平均值)
    hdu 3665(最短路)
    hdu 4463(最小生成树变形)
    hdu 2242(边双连通分量)
    hdu 2682(最小生成树)
    hdu 2444(二分图的判断以及求最大匹配)
    陶哲轩实分析命题6.4.12
    陶哲轩实分析习题8.3.4
    CantorBernsteinSchroeder定理的证明
  • 原文地址:https://www.cnblogs.com/gavanwanggw/p/7085554.html
Copyright © 2011-2022 走看看