我甚至跟书上敲的一摸一样了,还是全WA

P1464 Function

spindrift @ 2023-12-03 12:40:47

#include <iostream>
using namespace std;
long long int f[25][25][25];
long long int w(long long int a, long long int b, long long int c) {
    if (a <= 0 || b <= 0 || c <= 0) return 1;
    else if (a > 20 || b > 20 || c > 20) return w(20, 20, 20);
    else if (f[a][b][c] !=  0) return f[a][b][c];
    else if (a < b && b < c)
        f[a][b][c] = (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 int a, b, c;
    while (cin >> a >> b >> c) {
        if (a == -1 && b == -1 && c == -1)
            break;
        cout << "w(" << a << ", " << b << ", " << c << ") = ";
        cout << w(a, b, c) << endl;
    }
    return 0;
}

by xiaoni0v0 @ 2023-12-03 13:09:34

请检查你 w 函数体的第 5

你会对逗号表达式又爱又恨的,有时候很难发现这种错误...


by zhouzihang3 @ 2023-12-03 13:11:33

括号前面w没敲上/kk


by qweradf @ 2023-12-03 13:27:21

@xiaoni0v0 打开-Wall -Wextra即可避免。


by xiaoni0v0 @ 2023-12-03 13:46:48

@qwqer233 你猜我是怎么发现的?(doge


by spindrift @ 2023-12-04 11:04:43

@xiaoni0v0 啊 谢了 那天这玩意快给我整疯了


by spindrift @ 2023-12-04 11:05:10

@zero_egg qwq 真难发现啊


|