poj 1579 Function Run Fun
#include <iostream>
using namespace std;
int rec[21][21][21];
int w(int a,int b,int c)
{
if(a<=0||b<=0||c<=0)
return 1;
else if(a>20||b>20||c>20)
return w(20,20,20);
else if(rec[a][b][c]!=-1)
return rec[a][b][c];
else
{
int s;
if(a<b&&b<c)
s=w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c);
else
s=w(a-1,b,c)+w(a-1,b-1,c)+w(a-1,b,c-1)-w(a-1,b-1,c-1);
rec[a][b][c]=s;
return s;
}
}
int main()
{
int a,b,c;
memset(rec,-1,sizeof(rec));
while(cin>>a>>b>>c)
{
if(a==-1&&b==-1&&c==-1)
break;
printf("w(%d, %d, %d) = %d\n",a,b,c,w(a,b,c));
}
return 0;
}