This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "fish.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1005;
ll p[N][N],dp[N][N][5];
ll max_weights(int n, int m, vector<int> X, vector<int> Y, vector<int> W) {
for (int i = 0;i < m; i++){
X[i]++,Y[i]++;
p[X[i]][Y[i]] += W[i];
}
for (int j = 1; j <= n; j++)
for (int i = 1; i <= n; i++)
p[j][i] += p[j][i - 1];
for (int j = 2; j <= n; j++){
for (int a = 0; a <= n; a++){
//update dp[j][a][0]
for (int b = a; b <= n; b++){
ll v = max(dp[j - 1][b][0],dp[j - 1][b][1]);
dp[j][a][0] = max(dp[j][a][0], v + p[j][b] - p[j][a]);
}
//update dp[j][a][1]
for (int b = 0; b <= a; b++){
ll v = dp[j - 1][b][1];
dp[j][a][1] = max(dp[j][a][1], v + p[j - 1][a] - p[j - 1][b]);
}
//c 0 a
if (j >= 3){
for (int c = 0; c <= n; c++){
ll v = max(dp[j - 2][c][0],dp[j - 2][c][1]);
dp[j][a][1] = max(dp[j][a][1], v + p[j - 1][max(a,c)]);
}
}
}
}
ll ans = 0;
for (int a = 0; a <= n; a++)
ans=max(ans,max(dp[n][a][0],dp[n][a][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... |