#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void chmax(ll& x, ll y) {
x = max(x, y);
}
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
std::vector<int> W) {
vector<vector<ll>> a(N + 3, vector<ll>(N + 3));
for (int i = 0; i < M; ++i) {
a[X[i]][Y[i]] += W[i];
}
int L = min(N, 8);
const ll INF = 1e18;
ll dp[N][L + 1][L + 1][L + 1];
for (int i = 0; i < N; ++i) {
for (int j = 0; j < L + 1; ++j) {
for (int k = 0; k < L + 1; ++k) {
for (int l = 0; l < L + 1; ++l) {
dp[i][j][k][l] = -INF;
}
}
}
}
for (int i = 0; i < N; ++i) {
for (int j = 0; j < L + 1; ++j) {
for (int k = 0; k < L + 1; ++k) {
ll ndp = 0;
if (i > 0) {
for (int l = 0; l < L + 1; ++l) {
ndp = max(ndp, dp[i - 1][l][k][j]);
}
}
if (i == 0 && k != 0) ndp = -INF;
for (int l = 0; l < L + 1; ++l) {
ll add = 0;
int st = j;
int en = max(k, l);
for (int m = st; m < en; ++m) {
add += a[i][m];
}
if (i + 1 == N && l != 0) add = -INF;
chmax(dp[i][k][j][l], ndp + add);
}
}
}
}
ll res = 0;
for (int i = 0; i < L + 1; ++i) {
for (int j = 0; j < L + 1; ++j) {
for (int k = 0; k < L + 1; ++k) {
res = max(res, dp[N - 1][i][j][k]);
}
}
}
return res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |