HDU 1005 Number Sequence

暂不知道怎么办,递归层数过多

Runtime Error
(STACK_OVERFLOW)

#include <iostream>
using namespace std;
int A, B, n;
int func( int x )
{
    if( x == 1 || x == 2)
        return 1;
    else// x > 2
        return ( A * func( x - 1 ) + B * func( x - 2 ) ) % 7;
}
int main()
{
    while( cin >> A >> B >> n )
    {
        if( A==0 && B==0 && n==0 )
            break;
        cout << func(n) << endl;
    }
    return 0;
}

/*
Sample

1 1 3
1 2 10
0 0 0

*/
posted @ 2012-04-17 00:06  川川.aug  阅读(107)  评论(0编辑  收藏  举报