数据疑似过弱
查看原帖
数据疑似过弱
403719
Kasugano_Haruka楼主2022/3/11 09:22

如题, 我的代码没有考虑一个房间不偷完的情况, 同时也没有考虑后来看题解才发现的mm需要1-1的"坑点"(汗

但是还是可以过这题, 代码如下, 请忽略菜鸡的码风以及将链式前向星转化成邻接表的行为以及其他槽点...(

#include <bits/stdc++.h>

#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))

using namespace std;

__attribute__((unused)) typedef long long ll;
__attribute__((unused)) typedef unsigned long long ull;

__attribute__((unused)) inline ll read() {
    ll x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = (x << 1) + (x << 3) + (ch ^ 48);
        ch = getchar();
    }
    return x * f;
}

__attribute__((unused)) const int maxN = 1e2 + 4, maxM = 6e2 + 4, maxA = 14, maxB = 34, INF = 0x3f3f3f3f, MOD = 1e9 + 7;

int m;
struct node {
    int len = 0;
    int value = 0;
    int left = 0;
    int right = 0;

    node(int le = 0, int v = 0, int l = 0, int r = 0) : len(le), value(v), left(l), right(r) {}
};

int size = 0;
node a[maxN] = {};
int dp[maxN][maxM] = {};

void build(int t, int v) {
    int now = ++size;
    a[now].len = t;
    a[now].value = v;
    if (v)
        return;
    int tt = read(), vv = read();
    a[now].left = size + 1;
    build(tt, vv);
    tt = read(), vv = read();
    a[now].right = size + 1;
    build(tt, vv);
}

void dfs(int p) {
    const node &now = a[p];
    if (!now.left) {
        dp[p][2 * now.len + 5 * now.value] = now.value;
        return;
    }
    dfs(now.left);
    dfs(now.right);
    for (int i = m; i >= 2 * now.len; --i) {
        for (int j = 0; j <= i - 2 * now.len; ++j) {
            dp[p][i] = max(dp[p][i], dp[now.left][j] + dp[now.right][i - 2 * now.len - j]);
        }
    }
}

int main() {
//    debug();
    m = read();
    int t0 = read(), v0 = read();
    build(t0, v0);
    dfs(1);
    cout << dp[1][m];
}
2022/3/11 09:22
加载中...