Hdu 1165 Eddy & amp; #39; s research II (mathematical problem, recurrence)

Source: Internet
Author: User

// Continue with Eddy

Problem DescriptionAs 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 ).

InputEach 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.

OutputFor each value of m, n, print out the value of A (m, n ).

Sample Input
1 32 4

Sample Output
511

Authoreddy/******************** the first sight of this question is like recursion, then, according to the formula in the question, I found it difficult to find it. I first wrote a recursion, typed the table, and then, well, found the law ......

Tabulation. This is the real tabulation ......


If you see this table, you don't have to say the rule ......

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

Code: <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + PHByZSBjbGFzcz0 = "brush: java;"> # include # Include # Include 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", n + 2); if (m = 2) printf ("% d \ n ", 2 * n + 3); if (m = 3) printf ("% d \ n", num [n]);} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.