#include <bits/stdc++.h>
#include "fish.h"
using namespace std;
typedef long long ll;
ll max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) {
ll mat[n + 5][n + 5] = {}, pref[n + 5][n + 5] = {};
for (int i = 0; i < m; i ++)
mat[x[i] + 1][y[i] + 1] = w[i];
for (int i = 1; i <= n; i ++)
for (int j = 1; j <= n; j ++)
pref[i][j] = pref[i][j - 1] + mat[i][j];
ll dp[n + 1][n + 1][2] = {};
for (int k = 1; k <= n; k ++)
dp[1][k][0] = pref[2][k];
for (int i = 2; i <= n; i ++){
for (int k = 0; k <= n; k ++){
for (int pk = 0; pk <= n; pk ++){
if (k >= pk) dp[i][k][0] = dp[i - 1][pk][0] - pref[i][pk] + pref[i - 1][k] - pref[i - 1][pk] + pref[i + 1][k];
else dp[i][k][1] = max(dp[i - 1][pk][0], dp[i - 1][pk][1]) - pref[i][k] + pref[i + 1][k];
dp[i][k][0] = max(dp[i][k][0], max(dp[i - 2][pk][0], dp[i - 2][pk][1]) - pref[i - 1][pk] + pref[i - 1][max(pk, k)] + pref[i + 1][k]);
}
}
}
ll ans = 0;
for (int k = 0; k <= n; k ++)
ans = max(ans, max(dp[n][k][0], dp[n][k][1]));
return ans;
}
# | 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... |