이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define MAXN 510
#define inf 0x3f3f3f3f
using namespace std;
int n, vet[MAXN], dp[MAXN][100010], sum = 0, sa[MAXN];
inline int func(int u, int s1)
{
if(u == n+1 and s1 != 0) return inf;
if(u == n+1) return 0;
if(dp[u][s1] != -1) return dp[u][s1];
int p1 = func(u+1, s1+vet[u]);
int p2 = inf;
if(vet[u] <= s1) p2 = func(u+1, s1-vet[u]);
int p3 = func(u+1, s1);
if(p3 != inf) p3 += vet[u];
int menor = min({p1, p2, p3});
if(s1 == 0) menor = min(menor, sum-sa[u-1]);
return dp[u][s1] = menor;
}
int main()
{
cin >> n;
memset(dp, -1, sizeof dp);
sa[0] = 0;
for(int i = 1 ; i <= n ; i++)
{
cin >> vet[i];
sum += vet[i];
sa[i] = sa[i-1]+vet[i];
}
int result = func(1, 0);
cout << (sum-result)/2 + result << endl;
}
# | 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... |