蒟蒻记忆化全WA求助、

P1464 Function

achjuncool @ 2022-06-18 18:49:13

样例是对的,也不会爆(应该

代码如下:::::::

#include <iostream>
using namespace std;
long long x, y, z, r[25][25][25];
long long func(long long a, long long b, long long c){
    if(a <= 0 || b <= 0 || c <= 0){
        return 1;
    } else if(r[a][b][c] != 0){
        return r[a][b][c];
    } else if(a > 20 || b > 20 || c > 20){
        r[a][b][c] = func(20, 20, 20);
    } else if(a < b && b < c){
        r[a][b][c] = func(a, b, c - 1) + func(a, b - 1, c - 1) - func(a, b - 1, c);
    } else{
        r[a][b][c] = func(a - 1, b, c) + func(a - 1, b - 1, c) + func(a - 1, b, c - 1) - func(a - 1, b - 1, c - 1);
    }
}
int main() {
    cin >> x >> y >> z;
    while(x != -1 && y != -1 && z != -1){
        if(x > 20) x = 21;
        if(y > 20) y = 21;
        if(z > 20) z = 21;
        cout << "w(" << x << ", " << y << ", " << z << ") = " << func(x, y, z) << endl;
        cin >> x >> y >> z;
    }
    return 0;
}

by _maojun_ @ 2022-06-19 07:31:54

@achjuncool 那这个是在你的那基础上改的

while(x != -1 && y != -1 && z != -1){
        cout << "w(" << x << ", " << y << ", " << z << ") = ";
        if(x > 20) x = 21;
        if(y > 20) y = 21;
        if(z > 20) z = 21;
        if(x < 0) x = 0;
        if(y < 0) y = 0;
        if(z < 0) z = 0;
        cout << func(x, y, z) << endl;
        cin >> x >> y >> z;
    }

上一页 |