# BZOJ1084 最大子矩阵

### ｃｏｄｅ

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');}
template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('\n');}
template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);}
#define PAUSE printf("Press Enter key to continue..."); fgetc(stdin);
const int inf=1e6;
const int maxn=105;
int n,m,K,a;
int f[maxn][15],ff[maxn][maxn][15],s[maxn],sum[maxn][2];
/*==================Define Area================*/
int main() {
if (m==1) {
for (int i=1;i<=n;i++) {
s[i]=s[i-1]+a;
}
for (int i=0;i<=n;i++) {
for (int j=1;j<=K;j++) f[i][j]=-inf;
}
for (int i=1;i<=n;i++) {
for (int j=1;j<=K;j++) {
f[i][j]=f[i-1][j];
for (int i1=0;i1<i;i1++)
f[i][j]=max(f[i][j],f[i1][j-1]+s[i]-s[i1]);
}
}
printf("%d", f[n][K]);
}
else {
for (int i=1;i<=n;i++) {
for (int j=1;j<=m;j++) {
sum[i][j]=sum[i-1][j]+a;
}
}
for (int i=0;i<=n;i++) {
for (int j=0;j<=n;j++) {
for (int k=1;k<=K;k++) ff[i][j][k]=-inf;
}
}
for (int i=1;i<=n;i++) {
for (int j=1;j<=n;j++) {
for (int k=1;k<=K;k++) {
ff[i][j][k]=max(ff[i-1][j][k],ff[i][j-1][k]);
for (int i1=0;i1<i;i1++)
ff[i][j][k]=max(ff[i1][j][k-1]+sum[i][1]-sum[i1][1],ff[i][j][k]);
for (int j1=0;j1<j;j1++)
ff[i][j][k]=max(ff[i][j1][k-1]+sum[j][2]-sum[j1][2],ff[i][j][k]);
if (i==j) {
for (int i1=0;i1<i;i1++)
ff[i][i][k]=max(ff[i][i][k],ff[i1][i1][k-1]+sum[i][1]+sum[i][2]-sum[i1][1]-sum[i1][2]);
}
}
}
}
printf("%d", ff[n][n][K]);
}
}


posted @ 2018-08-07 10:54  Apocrypha  阅读(81)  评论(0编辑  收藏