一开始把f函数的第二个判断和第三个判断写反了
2y, 200k, 0ms
#include <iostream> #define F(i,a,b) for (int i=a;i<=b;i++) using namespace std; int g[21][21][21] ; int f(int a, int b, int c) { if (a<=0 || b <=0 || c<=0) return 1; if (a>20 || b > 20 || c > 20 ) return g[20][20][20] = f(20, 20, 20) ; if (g[a][b][c]-16843009) return g[a][b][c]; if ( a<b && b < c) return g[a][b][c] = f(a, b, c-1) + f(a, b-1, c-1) - f(a, b-1, c); return g[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; memset(g, 1, sizeof(g) ); while (scanf("%d%d%d", &a, &b, &c) && ( (a+1) || (b+1) || (c+1) ) ) printf("w(%d, %d, %d) = %d/n", a, b, c, f(a, b, c) ) ; return 0; }