蒟蒻求助!

P1464 Function

这道题目不是纯模拟吧= =
by _FILARET_ @ 2018-09-24 09:55:52


你还得加记忆化才能保证不超时
by _FILARET_ @ 2018-09-24 09:56:43


用时6000ms 太厉害了
by wxy_god @ 2018-09-24 10:03:04


@[XZRY520](/space/show?uid=77584) 纯模拟是绝对不行的 这是我的记忆化搜索 因该能看懂(其实跟您的差不多) ``` #include <cstdio> using namespace std; long long f[21][21][21]; long long 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 (f[a][b][c] == 0) { if (a < b && b < c) f[a][b][c] = w(a, b, c - 1) + w(a, b-1, c-1)-w(a, b-1, c); else f[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); return f[a][b][c]; } } int main() { long long a, b, c; while (true) { scanf ("%lld%lld%lld", &a, &b, &c); if (a == -1 && b == -1 && c == -1) break; printf ("w(%lld, %lld, %lld) = %lld\n", a, b, c, w(a, b, c)); } } ```
by wxy_god @ 2018-09-24 10:04:31


|