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 <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n, m, x, y, k;
ll max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> k) {
vector< vector<ll> > v(n, vector<ll>(n));
int mx = 0;
for (int i = 0; i < m; i++) {
v[x[i]][y[i]] += k[i];
mx = max(mx, y[i]);
}
mx++;
mx++;
// cout << "DEBUG" << endl;
vector< vector< vector< vector<ll> > > > dp(n, vector< vector< vector<ll> > > (mx, vector< vector<ll> > (mx, vector<ll>(mx))));
for (int i = 0; i < mx; i++) {
for (int j = 0; j < mx; j++) {
for (int i1 = i; i1 < j; i1++) {
// cout << mx << ' ' << i << ' ' << j << ' ' << i1 << endl;
dp[0][0][i][j] += v[0][i1];
}
// cout << dp[0][0][i][j] << endl;
}
}
// cout << "DEBUG" << endl;
ll ans = 0;
for (int x = 1; x < n; x++) {
for (int i = 0; i < mx; i++) {
for (int j = 0; j < mx; j++) {
ll mx1 = 0;
for (int k = 0; k < mx; k++) {
mx1 = max(mx1, dp[x - 1][k][i][j]);
}
for (int k = 0; k < (x == n - 1 ? 1 : mx); k++) {
dp[x][i][j][k] = mx1;
// if (x == 1 && i == 0 && j == 3 && k == 5) {
// cout << mx1 << endl;
// }
for (int i1 = j; i1 < max(i, k); i1++) {
dp[x][i][j][k] += v[x][i1];
}
if (x == n - 1) {
ans = max(ans, dp[x][i][j][k]);
}
}
}
}
}
// cout << endl;
// cout << dp[0][0][0][3] << endl;
// cout << dp[1][0][3][5] << endl;
// cout << dp[2][3][5][0] << endl;
// cout << dp[3][5][0][4] << endl;
// cout << dp[4][0][4][0] << endl;
return ans;
}
//void solve() {
// cin >> n >> m;
// vector<int> x(m);
// vector<int> y(m);
// vector<int> k(m);
// for (int i = 0; i < m; i++) {
// cin >> x[i] >> y[i] >> k[i];
// }
// cout << max_weights(n, m, x, y, k) << '\n';
//}
//
//int main() {
// ios_base::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
// solve();
//}
# | 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... |