이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const long long maxn = 2048;
long long n,a,b;
long long age[maxn];
long long par[maxn];
long long dp[maxn][maxn];
void read()
{
cin >> n >> a >> b;
for( long long i = 1; i <= n; i ++ )
cin >> age[i];
}
void solve()
{
memset(dp,-1,sizeof(dp));
for( long long i = 1; i <= n; i ++ )
par[i] = par[i-1] + age[i];
for( long long i = 1; i <= n; i ++ )
dp[i][1] = par[i];
for( long long j = 2; j <= b; j ++ )
{
for( long long i = j; i <= n; i ++ )
{
for( long long k = i; k > j-1; k -- )
{
if( dp[k-1][j-1] == -1 ) continue;
long long x = ( dp[k-1][j-1] | ( par[i] - par[k-1] ) );
if( dp[i][j] == -1 || x < dp[i][j] ) dp[i][j] = x;
}
}
}
long long ans = -1;
for( long long i = a; i <= b; i ++ )
if( ans == -1 || dp[n][i] < ans ) ans = dp[n][i];
cout << ans << '\n';
}
int main()
{
read();
solve();
return 0;
}
/*
6 1 3
8 1 2 1 5 4
*/
| # | 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... |