思路:用数组w[a][b][c]保存,减少重复搜索
#include<stdio.h>
#include<string.h>
#define MAX 25
int x[MAX][MAX][MAX];
int w(int a,int b,int c){
if(a<=0||b<=0||c<=0)return 1;
if(a>20||b>20||c>20)return w(20,20,20);
if(x[a][b][c]!=0)return x[a][b][c];
if(a<b&&b<c)return x[a][b][c] = w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c);
else return x[a][b][c] = w(a-1,b,c)+w(a-1,b-1,c)+w(a-1,b,c-1)-w(a-1,b-1,c-1);
}
int main(){
int a,b,c;
memset(x,0,sizeof(x));
while(~scanf("%d%d%d",&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;
}