题目:http://www.gdfzoj.com/oj/contest/155/problems/4
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
long long f[20+5][20+5][20+5];
void dg()
{
int i,j,k;
for (i=0;i<=20;i++)
{
for (j=0;j<=20;j++)
{
for (k=0;k<=20;k++)
{
if (i==0 || j==0 || k==0)
f[i][j][k]=1;
else if (i<j && j<k)
f[i][j][k]=f[i][j][k-1]+f[i][j-1][k-1]-f[i][j-1][k];
else
f[i][j][k]=f[i-1][j][k]+f[i-1][j-1][k]+f[i-1][j][k-1]-f[i-1][j-1][k-1];
}
}
}
}
int main()
{
int i,x,y,z;
freopen("a.txt","r",stdin);
dg();
while (1)
{
scanf("%d%d%d",&x,&y,&z);
if (x==-1 && y==-1 && z==-1)
break;
printf("w(%d, %d, %d) = ",x,y,z);
if (x<=0 || y<=0 || z<=0)
printf("%lld\n",f[0][0][0]);
else if (x>20 || y>20 || z>20)
printf("%lld\n",f[20][20][20]);
else
printf("%lld\n",f[x][y][z]);
}
return 0;
}