이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int MAX_S = 1e5 + 42;
const int MAX_N = 512;
const int INF = 1e9;
const int mod = 1e9 + 7;
int dp[MAX_N][MAX_S/2];
int a[MAX_N];
int sum;
int n;
int sol( int pos, int diff )
{
if( diff > sum / 2 )
{
return -INF;
}
if( dp[pos][diff] != -1 )
{
return dp[pos][diff];
}
if( pos == n )
{
if( diff == 0 )
{
return 0;
}
return -INF;
}
int currNas = 0;
currNas = max({ sol(pos+1, diff), sol(pos+1, diff + a[pos]) + a[pos], sol( pos+1, abs( diff - a[pos] ) ) + max(0, a[pos] - diff) } );
return dp[pos][diff] = currNas;
}
int main ()
{
cin>>n;
for( int i=0 ; i<n ; i++)
{
cin>>a[i];
sum += a[i];
}
memset( dp, -1, sizeof(dp) );
int nas = sol( 0, 0 );
nas += ( sum - nas*2 );
cout<<nas<<"\n";
return 0;
}
| # | 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... |