# BZOJ1084 最大子矩阵

Description

Input

Output

Sample Input
3 2 2
1 -3
2 3
-2 3
Sample Output
9

#include<iostream>
#include<cstdio>
using namespace std;

int sum[101],s1[101],s2[101];
int dp[101][11],f[101][101][11];

int main()
{
int n,m,K;
cin >> n >> m >> K;
if (m==1)
{
for (int i=1; i<=n; i++) { int now; cin >> now; sum[i]=sum[i-1]+now; }
for (int i=1; i<=n; i++)
for (int k=1; k<=K; k++)
{
dp[i][k]=dp[i-1][k];
for(int j=0; j<i; j++) dp[i][k]=max(dp[i][k],dp[j][k-1]+sum[i]-sum[j]);
}
cout << dp[n][K] << endl;
return 0;
}
int s,ss;
for (int i=1; i<=n; i++) { scanf("%d%d",&s,&ss); s1[i]=s1[i-1]+s; s2[i]=s2[i-1]+ss; }
for (int k=1; k<=K; k++)
for (int i=1; i<=n; i++)
for (int j=1; j<=n; j++)
{
f[i][j][k]=max(f[i-1][j][k],f[i][j-1][k]);
for (int l=0; l<i; l++)  f[i][j][k]=max(f[i][j][k],f[l][j][k-1]+s1[i]-s1[l]);
for (int l=0; l<j; l++)  f[i][j][k]=max(f[i][j][k],f[i][l][k-1]+s2[j]-s2[l]);
if (i==j)
for (int l=0; l<i; l++) f[i][j][k]=max(f[i][j][k],f[l][l][k-1]+s1[i]-s1[l]+s2[j]-s2[l]);
}
cout << f[n][n][K] << endl;
return 0;
}

posted @ 2015-07-11 08:51  竹夭公子  阅读(185)  评论(0编辑  收藏