This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <algorithm>
#include <iostream>
#include <fstream>
#include <cstring>
#include <string>
#include <vector>
#include <cstdio>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
const long long N=105;
const long long inf=1e18;
#define MP make_pair
#define PB push_back
ll n,m,i,j,k,ans[N][N][N],a[N],x;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>k;
for(i=1;i<=n;i++)
cin>>a[i];
for(i=1;i<=n;i++)
for(j=i;j<=n;j++)
for(x=i;x<=j;x++)
ans[i][j][1]=max(ans[i][j][1],a[x]);
for(ll qanak=1;qanak<=k;qanak++)
{
for(i=1;i<=n;i++)
{
for(j=i;j<=n;j++)
{
ans[i][j][qanak+1]=inf;
for(x=i;x<=j-qanak;x++)
ans[i][j][qanak+1]=min(ans[i][j][qanak+1],ans[i][x][1]+ans[x+1][j][qanak]);
}
}
}
cout<<ans[1][n][k]<<endl;
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... |