이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxS = 1e5 + 5;
const int INF = 1e9 + 5;
int dp[105][100][100];
vector<int> a;
int n;
int go(int k, int x, int y) {
if (dp[k][x][y] != -1) {
return dp[k][x][y];
}
int& ret = dp[k][x][y];
if (k == n) {
return ret = (x == y ? 0 : -INF);
}
return ret = max({go(k+1, x, y), go(k+1, x+a[k], y)+a[k], go(k+1, x, y+a[k])+a[k]});
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
memset(dp, -1, sizeof dp);
cin >> n;
a.resize(n);
for(int i = 0; i < n; i++) {
cin >> a[i];
}
int sum = accumulate(a.begin(), a.end(), 0);
int sol = go(0, 0, 0);
cout << (sol / 2) + (sum - sol);
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |