就是将所给的公式写出来就ok啦
#include <iostream>
using namespace std;
int f[25][25][25], a, b, c;
int w ( int a, int b, int c ) {
if ( a <= 0 || b <= 0 || c <= 0 )
f[a][b][c] = 1;
else if ( a < b && b < c )
f[a][b][c] = f[a][b][c - 1] + f[a][b - 1][c - 1] - f[a][b - 1][c];
else {
f[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 ( ) {
for ( int i = 0; i < 21; ++i )
for ( int j = 0; j < 21; ++j )
for ( int k = 0; k < 21; ++k )
w ( i, j, k );
while ( cin >> a >> b >> c ) {
if ( a == -1 && b == -1 && c == -1 ) break;
cout << "w(" << a << ", " << b << ", " << c << ") = ";
if ( a <= 0 || b <= 0 || c <= 0 ) {
cout << "1" << endl;
continue;
}
else if ( a > 20 || b > 20 || c > 20 ) {
cout << f[20][20][20] << endl;
continue;
}
cout << f[a][b][c] << endl;
}
}