이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int MAX=2005;
ll dp[MAX][205];
ll tab[MAX];
int pref[MAX];
ll prefix(int a,int b)
{
return pref[b]-pref[a-1];
}
vi ans;
int32_t main()
{
BOOST;
int n,k;
cin>>n>>k;
for (int i=1;i<=n;i++)cin>>tab[i];
for (int i=1;i<=n;i++)pref[i]=pref[i-1]+tab[i];
for (int i=1;i<=n;i++)
for (int j=i;j>=2;j--)
for (int l=1;l<=k;l++)
dp[i][l]=max(dp[i][l],prefix(j,i)*prefix(1,j-1)+dp[j-1][l-1]);
cout<<dp[n][k]<<"\n";
int wsk=n;
for (int i=k;i>=1;i--)
for (int j=wsk;j>=2;j--)
if (dp[wsk][i]==prefix(j,wsk)*prefix(1,j-1)+dp[j-1][i-1])
{
wsk=j-1;
ans.pb(j-1);
break;
}
for (auto it:ans)cout<<it<<" ";
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... |