1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | #include <iostream> using namespace std; int dp[101][101][101] = {0}; 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 dp[20][20][20]; } else { return dp[a][b][c]; } } int main() { for (int a = 0; a <= 20; a++) { for (int b = 0; b <= 20; b++) { for (int c = 0; c <= 20; c++) { if (a == 0 || b == 0 || c == 0) { dp[a][b][c] = 1; } else if (a < b && b < c) { dp[a][b][c] = dp[a][b][c – 1] + dp[a][b – 1][c – 1] – dp[a][b – 1][c]; } else { dp[a][b][c] = dp[a – 1][b][c] + dp[a – 1][b – 1][c] + dp[a – 1][b][c – 1] – dp[a – 1][b – 1][c – 1]; } } } } while (true) { int a, b, c; cin >> a >> b >> c; if (a == –1 and b == –1 and c == –1) { break; } printf(“w(%d, %d, %d) = %d\n”, a, b, c, w(a, b, c)); } } | cs |