0分求助

P1464 Function

12345limengqi @ 2023-12-14 17:26:24

#include <iostream>
using namespace std;
#define ll long long
ll l[22][22][22] = {0};
ll w(ll a, ll b, ll c){
    if(a <= 0 || b <= 0 || c <= 0){
        return 1;
    }
    if(a > 20 || b > 20 || c > 20){
        return w(20, 20, 20);
    }
    if(l[a][b][c] != 0){
        return l[a][b][c];
    }
    if(a < b && b < c){
        l[a][b][c] = w(a, b, c - 1) + w(a, b - 1, c - 1) - w(a, b - 1, c);
    }
    else {
        l[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);
    }
}
int main () {
    ll a, b, c;
    while(true){
        cin >> a >> b >> c;
        if(a == -1 && b == -1 && c == -1){
            break;
        }
        printf("w(%d, %d, %d) = %d\n", a, b, c, w(a, b, c));
    }
    return 0;
}//样例过了

by 12345limengqi @ 2023-12-14 17:28:30

回复我,记得@一下,谢谢


by 12345limengqi @ 2023-12-14 17:30:51

0分记录


by Obijeb @ 2023-12-14 17:59:32

@12345limengqi

当l[a][b][c]=0时做了记忆化但没有返回值,在函数结尾return l[a][b][c]即可

(通常函数末尾没有返回值编译器都会警告)


by 12345limengqi @ 2023-12-14 18:04:41

可是附加的两个点没过啊


by 12345limengqi @ 2023-12-14 18:31:44

不过也是感谢


by 12345limengqi @ 2023-12-14 18:32:14

@DD20070520 已关注


by Obijeb @ 2023-12-14 18:52:56

@12345limengqi

输出a,b,c的时候要用%lld

亲测已过


by 12345limengqi @ 2023-12-14 20:35:15

感谢


|