RE求调

P1464 Function

@[Channel_09](https://www.luogu.com.cn/user/787888) 有4个错误: 1.flag数组不用开 2.if (a < b && b < c)判断部分记忆数组sum要等于这个递归函数的运算: ``` return sum[a][b][c] = W(a,b,c - 1) + W(a,b - 1,c - 1) - W(a,b - 1,c); ``` ``` return sum[a][b][c] = W(a - 1,b,c - 1) + W(a - 1,b - 1,c) + W(a - 1,b,c) - W(a - 1,b - 1,c - 1); ``` 3.为了防止多次调用滥用时间,判断sum是否有数,有数输出,无数存起来 4.输出错了: ``` cout<<"w("<<u<<", "<<v<<", "<<w<<") = "<<W(u,v,w)<<endl; ``` ## 下面是改的代码: ------------ ``` #include <iostream> using namespace std; long long sum[100][100][100] = { 0 }; long long W(long long a, long long b, long long c) { if (a <= 0 || b <= 0 || c <= 0) { return 1; } else if (a > 20 || b > 20 || c > 20) { return W(20, 20, 20); }if(sum[a][b][c] > 0) return sum[a][b][c]; else if (a < b && b < c) { return sum[a][b][c] = W(a,b,c - 1) + W(a,b - 1,c - 1) - W(a,b - 1,c); } else { return sum[a][b][c] = W(a - 1,b,c - 1) + W(a - 1,b - 1,c) + W(a - 1,b,c) - W(a - 1,b - 1,c - 1); } } int main() { while (true) { long long u, v, w; cin >> u >> v >> w; if (u == -1 && v == -1 && w == -1) { break; } cout<<"w("<<u<<", "<<v<<", "<<w<<") = "<<W(u,v,w)<<endl; } return 0; } ```
by Chicken_cooked_fish @ 2024-06-10 14:13:12


中间if (a < b && b < c)太复杂了,我精简了一下
by Chicken_cooked_fish @ 2024-06-10 14:14:20


@[Chicken_cooked_fish](/user/1043998) 谢谢大犇帮忙! orz
by Channel_Choo @ 2024-06-10 15:34:09


@[Chicken_cooked_fish](/user/1043998) 没RE了,但WA,样例也是能过得
by Channel_Choo @ 2024-06-10 15:55:55


@[Channel_09](/user/787888) 输出错了
by Chicken_cooked_fish @ 2024-06-10 16:14:16


``` cout<<"w("<<u<<", "<<v<<", "<<w<<") = "<<W(u,v,w)<<endl; ``` ,后面有空格
by Chicken_cooked_fish @ 2024-06-10 16:14:57


@[Channel_09](/user/787888)
by Chicken_cooked_fish @ 2024-07-08 18:00:38


输出错了
by Chicken_cooked_fish @ 2024-07-08 18:01:02


|