最后一个测试点卡了,求调
查看原帖
最后一个测试点卡了,求调
1562283
Mikumikumi123楼主2025/1/20 16:04

最后一个测试点卡了,求调

#include<iostream>
using namespace std;
#define ll long long;
long long dp[21][21][21] = { 0 };
long long func(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 func(20, 20, 20);
    }
    else if (a < b && b < c) {
        long long y, y1, y2, y3;
        if (dp[a][b][c] == 0) {
            if (dp[a][b][c - 1] == 0)y1 = func(a, b, c - 1),dp[a][b][c - 1] = y1;
            else y1 = dp[a][b][c - 1];
            if (dp[a][b - 1][c - 1] == 0) y2 = func(a, b - 1, c - 1), dp[a][b - 1][c - 1] = y2;
            else y2 = dp[a][b - 1][c - 1];
            if (dp[a][b][c - 1] == 0) y3 = func(a, b - 1, c), dp[a][b][c - 1] = y3;
            else y3 = dp[a][b][c - 1];
            y = y1 + y2 - y3;
            dp[a][b][c] = y;
        }
        else {
            y = dp[a][b][c];
        }
        return y;
    }
    else {
        long long z, z1, z2, z3, z4;
        if (dp[a][b][c] == 0) {
            if (dp[a - 1][b][c] == 0)z1 = func(a - 1, b, c), dp[a - 1][b][c] = z1;
            else z1 = dp[a - 1][b][c];
            if (dp[a - 1][b - 1][c] == 0)z2 = func(a - 1, b - 1, c), dp[a - 1][b - 1][c] = z2;
            else z2=dp[a - 1][b - 1][c];
            if (dp[a - 1][b][c - 1] == 0)z3 = func(a - 1, b, c - 1), dp[a - 1][b][c - 1] = z3;
            else z3 = dp[a - 1][b][c - 1];
            if (dp[a - 1][b - 1][c - 1] == 0)z4 = func(a - 1, b - 1, c - 1), dp[a - 1][b - 1][c - 1] = z4;
            else z4 = dp[a - 1][b - 1][c - 1];
            z = z1 + z2 + z3 - z4;
            dp[a][b][c] = z;
        }
        else {
            z = dp[a][b][c];
        }
        return z;
    }
}
int main() {
    long long a, b, c;
    long long ans[10000][4];
    int i = 0;
    do {
        cin >> a >> b >> c;
        d = func(a, b, c);
        ans[i][0] = a;
        ans[i][1] = b;
        ans[i][2] = c;
        ans[i][3] = d;
        i++;
    } while (a != -1 || b != -1 || c != -1);
    for (int j = 0;j < i - 1;j++) {
        cout << "w(" << ans[j][0] << ", " << ans[j][1]
            << ", " << ans[j][2] << ") = " << ans[j][3] << endl;
    }
    return 0;
}

2025/1/20 16:04
加载中...