0
#include <stdio.h>

#define MAXSIZE 100
int memo[MAXSIZE][MAXSIZE];
int aukermann(int m, int n)
{
    if (memo[m][n] != -1)
        return memo[m][n];
    if (m == 0)
        return (memo[m][n] = n + 1);
    else if (n == 0)
        return (memo[m][n] = aukermann(m - 1, 1));
    else {
        memo[m][n-1] = aukermann(m, n-1);
        return (memo[m][n] = aukermann(m - 1, memo[m][n-1]));
    }
}
main()
{
    int m, n;
    int i,j;
    for (i = 0; i < MAXSIZE; ++i)
        for (j = 0; j < MAXSIZE; ++j)
            memo[i][j] = -1;
    scanf("%d %d", &m, &n);
    printf("%d\n", aukermann(m, n));
    for (i = 0; i < 5; ++i) {
        for (j = 0; j < 62; ++j)
            printf("%d ", memo[i][j]);
        printf("\n");
    }
    return 0;
}

Its is showing correct result till (2,48) then showing wrong answers for m = 2 and n >= 49 due to which I'm getting wrong answer for m = 3 n >= 4.
Please Help!

2
Contributors
1
Reply
3
Views
4 Years
Discussion Span
Last Post by dooma
1

The problem is n varbiable, because it increment over 100. When your n is 0, it make m = 0 and after that your n grow over and over till goes out of length!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.