#include<stdio.h>
int max(int a, int b){return a>b?a:b;}
int min(int a, int b){return a<b?a:b;}
int dp[101][100001];
int IT[300001];
int b = 1;
int a[100001];
void setT(int *dest, int *src, int s, int e, int f, int r);
int getmax(int f, int r)
{
f+=b; r+=b;
int re = 0;
while(f<r)
{
if(f%2 == 1) re = max(re, IT[f++]);
if(r%2 == 0) re = max(re, IT[r--]);
f/=2; r/=2;
}
if(f==r) re = max(re, IT[f]);
return re;
}
int main()
{
int n, k;
int i, j;
scanf("%d%d", &n, &k);
for(b=1; b<=n; b*=2);
for(i=1; i<=n; i++)
{
scanf("%d", a+i);
IT[b+i] = a[i];
}
for(i=b; i>=1; i--) IT[i] = max(IT[i*2], IT[i*2+1]);
for(i=1; i<=n; i++) dp[1][i] = getmax(1, i);
for(i=2; i<=k; i++)
{
for(j=i; j<=n; j++)
{
dp[i][j] = dp[i-1][i-1] + getmax(i, j);
for(int k=i; k<=j-1; k++) dp[i][j] = min(dp[i][j], dp[i-1][k] + getmax(k+1, j));
}
}
printf("%d", dp[k][n]);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
42100 KB |
Output is correct |
2 |
Correct |
0 ms |
42100 KB |
Output is correct |
3 |
Correct |
0 ms |
42100 KB |
Output is correct |
4 |
Correct |
0 ms |
42100 KB |
Output is correct |
5 |
Correct |
0 ms |
42100 KB |
Output is correct |
6 |
Correct |
0 ms |
42100 KB |
Output is correct |
7 |
Correct |
0 ms |
42100 KB |
Output is correct |
8 |
Correct |
0 ms |
42100 KB |
Output is correct |
9 |
Correct |
0 ms |
42100 KB |
Output is correct |
10 |
Correct |
0 ms |
42100 KB |
Output is correct |
11 |
Correct |
0 ms |
42100 KB |
Output is correct |
12 |
Correct |
0 ms |
42100 KB |
Output is correct |
13 |
Correct |
2 ms |
42100 KB |
Output is correct |
14 |
Correct |
0 ms |
42100 KB |
Output is correct |
15 |
Correct |
0 ms |
42100 KB |
Output is correct |
16 |
Correct |
0 ms |
42100 KB |
Output is correct |
17 |
Correct |
0 ms |
42100 KB |
Output is correct |
18 |
Correct |
0 ms |
42100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
42100 KB |
Output is correct |
2 |
Correct |
0 ms |
42100 KB |
Output is correct |
3 |
Correct |
0 ms |
42100 KB |
Output is correct |
4 |
Correct |
0 ms |
42100 KB |
Output is correct |
5 |
Correct |
0 ms |
42100 KB |
Output is correct |
6 |
Correct |
0 ms |
42100 KB |
Output is correct |
7 |
Correct |
0 ms |
42100 KB |
Output is correct |
8 |
Correct |
0 ms |
42100 KB |
Output is correct |
9 |
Correct |
0 ms |
42100 KB |
Output is correct |
10 |
Correct |
0 ms |
42100 KB |
Output is correct |
11 |
Correct |
0 ms |
42100 KB |
Output is correct |
12 |
Correct |
0 ms |
42100 KB |
Output is correct |
13 |
Correct |
0 ms |
42100 KB |
Output is correct |
14 |
Correct |
0 ms |
42100 KB |
Output is correct |
15 |
Correct |
0 ms |
42100 KB |
Output is correct |
16 |
Correct |
0 ms |
42100 KB |
Output is correct |
17 |
Correct |
0 ms |
42100 KB |
Output is correct |
18 |
Correct |
0 ms |
42100 KB |
Output is correct |
19 |
Correct |
0 ms |
42100 KB |
Output is correct |
20 |
Correct |
0 ms |
42100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
42100 KB |
Output is correct |
2 |
Correct |
0 ms |
42100 KB |
Output is correct |
3 |
Correct |
0 ms |
42100 KB |
Output is correct |
4 |
Correct |
0 ms |
42100 KB |
Output is correct |
5 |
Correct |
0 ms |
42100 KB |
Output is correct |
6 |
Correct |
0 ms |
42100 KB |
Output is correct |
7 |
Correct |
0 ms |
42100 KB |
Output is correct |
8 |
Correct |
0 ms |
42100 KB |
Output is correct |
9 |
Correct |
0 ms |
42100 KB |
Output is correct |
10 |
Correct |
0 ms |
42100 KB |
Output is correct |
11 |
Correct |
0 ms |
42100 KB |
Output is correct |
12 |
Correct |
0 ms |
42100 KB |
Output is correct |
13 |
Correct |
5 ms |
42100 KB |
Output is correct |
14 |
Correct |
5 ms |
42100 KB |
Output is correct |
15 |
Correct |
8 ms |
42100 KB |
Output is correct |
16 |
Correct |
4 ms |
42100 KB |
Output is correct |
17 |
Correct |
4 ms |
42100 KB |
Output is correct |
18 |
Correct |
3 ms |
42100 KB |
Output is correct |
19 |
Correct |
4 ms |
42100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1000 ms |
42096 KB |
Program timed out |
2 |
Halted |
0 ms |
0 KB |
- |