# bzoj1084: [SCOI2005]最大子矩阵 dp

/**************************************************************
Problem: 1084
User: walfy
Language: C++
Result: Accepted
Time:748 ms
Memory:2716 kb
****************************************************************/

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define cd complex<double>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0)

using namespace std;

const double eps=1e-6;
const int N=100+10,maxn=5000+10,inf=0x3f3f3f3f,INF=0x3f3f3f3f3f3f3f3f;

int n,m,K;
ll a[N][3],sum[N][4],ma[N][N][4];
ll dp[N][N][11];
void prepare()
{
if(m==1)
{
for(int j=1;j<=n;j++)a[j][2]=-1e9;
m=2;
}
for(int i=1;i<=n;i++)
{
sum[i][1]=sum[i-1][1]+a[i][1];
sum[i][2]=sum[i-1][2]+a[i][2];
sum[i][3]=sum[i-1][3]+a[i][1]+a[i][2];
}
for(int i=1;i<=3;i++)
{
for(int j=0;j<=n;j++)
{
for(int k=j+1;k<=n;k++)
{
for(int l=j;l<=k;l++)
{
ma[j][k][i]=max(ma[j][k][i],sum[k][i]-sum[l][i]);
}
}
}
}
}
void gao()
{
for(int i=1;i<=K;i++)
{
for(int j=0;j<=n;j++)
{
for(int k=0;k<=n;k++)
{
for(int l=j+1;l<=n;l++)
{
dp[l][k][i]=max(dp[l][k][i],dp[j][k][i-1]+ma[j][l][1]);
}
for(int l=k+1;l<=n;l++)
{
dp[j][l][i]=max(dp[j][l][i],dp[j][k][i-1]+ma[k][l][2]);
}
for(int l=max(j,k)+1;l<=n;l++)
{
dp[l][l][i]=max(dp[l][l][i],dp[j][k][i-1]+ma[max(j,k)][l][3]);
}
}
}
}
ll ans=0;
for(int i=0;i<=n;i++)
for(int j=0;j<=n;j++)
for(int k=0;k<=K;k++)
ans=max(ans,dp[i][j][k]);
printf("%lld\n",ans);
}
int main()
{
scanf("%d%d%d",&n,&m,&K);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
scanf("%lld",&a[i][j]);
prepare();
gao();
return 0;
}
/********************

********************/
View Code

posted @ 2018-05-22 19:41  walfy  阅读(70)  评论(0编辑  收藏