再帰の関数---再帰の記憶化

3573 ワード

再帰関数Time Limit:1000 MS Memory Limit:65536 KB Submit Static Problem Description
関数f(a,b,c):a≦0またはb≦0またはc≦0の戻り値が1の場合.a>20またはb>20またはc>20の戻り値がf(20,20,20)である場合.aInput
入力は複数のテストデータを含み、各テストデータに対して、1動作3個の整数a,b,c(a,b,c<30)のみを入力する.
Output
各テストデータのセットについて、関数の計算結果を出力します.
Example Input
1 1 1
2 2 2
Example Output
2
4
#include 
using namespace std;
int x[31][31][31]={0};
int f( int a, int b, int c)
{
    if(a<=0||b<=0||c<=0)  return 1;
    else if(a>20||b>20||c>20) return f(20,20,20);
    else if (x[a][b][c]) return x[a][b][c];
    else if(areturn x[a][b][c]=f(a,b,c-1)+f(a,b-1,c-1)-f(a,b-1,c-1);
    else  return x[a][b][c]=f(a-1,b,c)+f(a-1,b-1,c)+f(a-1,b,c-1)-f(a-1,b-1,c-1);
}
int main()
{
    int a,b,c;
    while (cin>>a>>b>>c)
    {
        cout<a,b,c)<;
    }
    return 0;
}