# 【BZOJ1084】dp

#include <bits/stdc++.h>
#define sc(n) scanf("%d",&n)
#define pt(n) printf("%d\n",n)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
using namespace std;
const int maxn = 110;
int s1[maxn],s2[maxn];
int n,m,k;
int dp[maxn][maxn][maxn];
int main(http://www.my516.com)
{
scanf("%d%d%d",&n,&m,&k);
if(m==1)
{
for(int i=1;i<=n;i++)
{
int x;
scanf("%d",&x);
s1[i] = s1[i-1]+x;
}
for(int l=1;l<=k;l++)
{
for(int i=1;i<=n;i++)
{
dp[i][l][0] = dp[i-1][l][0];
for(int j=0;j<i;j++)
{
dp[i][l][0] = max(dp[i][l][0],dp[j][l-1][0]+s1[i]-s1[j]);
}
}
}
printf("%d\n",dp[n][k][0]);
}
else
{
for(int i=1;i<=n;i++)
{
int x,y;
scanf("%d%d",&x,&y);
s1[i] = s1[i-1]+x;
s2[i] = s2[i-1]+y;
}
for(int l=1;l<=k;l++)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
dp[i][j][l] = max(dp[i-1][j][l],dp[i][j-1][l]);
for(int s=0;s<i;s++)
{
dp[i][j][l] = max(dp[i][j][l],dp[s][j][l-1]+s1[i]-s1[s]);
}
for(int s=0;s<j;s++)
{
dp[i][j][l] = max(dp[i][j][l],dp[i][s][l-1]+s2[j]-s2[s]);
}
if(i==j)
{
for(int s=0;s<i;s++)
{
dp[i][j][l] = max(dp[i][j][l],dp[s][s][l-1]+s1[i]-s1[s]+s2[j]-s2[s]);
}
}
}
}
}
printf("%d\n",dp[n][n][k]);
}
return 0;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75

---------------------

posted on 2019-06-30 11:34  激流勇进1  阅读(38)  评论(0编辑  收藏