# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
763344 | raysh07 | 메기 농장 (IOI22_fish) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
#define INF (int)(1e18)
const int N = 305;
long long a[N][N];
long long dp[N][N][N];
int val(int i, int r1, int r2){
if (r2 > r1) return 0;
return a[i][r1] - a[i][r2];
}
long long max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) {
if (n > 300) return 0LL;
for (int i = 0; i < m; i++){
a[x[i] + 1][y[i] + 1] += w[i];
}
for (int i = 1; i <= n; i++){
for (int j = 1; j <= n; j++){
a[i][j] += a[i][j - 1];
}
}
return max(a[1][n], a[2][n]);
for (int i = 0; i < N; i++){
for (int j = 0; j < N; j++){
for (int k = 0; k < N; k++){
dp[i][j][k] = -INF;
}
}
}
for (int i = 1; i <= n; i++){
dp[1][i][0] = 0;
}
for (int i = 2; i <= n + 1; i++){
for (int c = 0; c <= n; c++){
for (int l1 = 0; l1 <= n; l1++){
for (int l2 = 0; l2 <= n; l2++){
//calculate for l1
dp[i][c][l1] = max(dp[i][c][l1] , dp[i - 1][l1][l2] + val(i - 1, max(c, l2), l1));
}
}
}
}
long long ans = -INF;
for (int i = 0; i <= 0; i++){
for (int j = 0; j <= n; j++){
ans = max(ans, dp[n + 1][i][j]);
}
}
return ans;
}
int main(){
int n, m; cin >> n >> m;
vector <int> a(m), b(m), c(m);
for (auto &x : a) cin >> x;
for (auto &x : b) cin >> x;
for (auto &x : c) cin >> x;
cout << max_weights(n, m, a, b, c) << "\n";
return 0;
}