# bzoj1084【SCOI2005】最大子矩阵

## 1084: [SCOI2005]最大子矩阵

Time Limit: 10 Sec  Memory Limit: 162 MB
Submit: 1946  Solved: 970
[Submit][Status][Discuss]

3 2 2
1 -3
2 3
-2 3

9

## Source

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define F(i,j,n) for(int i=j;i<=n;i++)
#define D(i,j,n) for(int i=j;i>=n;i--)
#define ll long long
#define inf 1000000000
using namespace std;
int n,m,k;
int f[105][15],g[105][105][15],s[105][3];
{
int x=0,f=1;char ch=getchar();
while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int main()
{
memset(s,0,sizeof(s));
if (m==1)
{
memset(f,0,sizeof(f));
F(i,1,n) F(j,1,k)
{
f[i][j]=f[i-1][j];
F(l,0,i-1) f[i][j]=max(f[i][j],f[l][j-1]+s[i][1]-s[l][1]);
}
printf("%d\n",f[n][k]);
}
else
{
memset(g,0,sizeof(g));
F(i,1,n) F(j,1,n) F(l,1,k)
{
g[i][j][l]=max(g[i-1][j][l],g[i][j-1][l]);
F(h,0,i-1) g[i][j][l]=max(g[i][j][l],g[h][j][l-1]+s[i][1]-s[h][1]);
F(h,0,j-1) g[i][j][l]=max(g[i][j][l],g[i][h][l-1]+s[j][2]-s[h][2]);
if (i==j) F(h,0,i-1)
g[i][j][l]=max(g[i][j][l],g[h][h][l-1]+s[i][1]-s[h][1]+s[j][2]-s[h][2]);
}
printf("%d\n",g[n][n][k]);
}
return 0;
}


posted @ 2017-06-19 10:57  zhchoutai  阅读(68)  评论(0编辑  收藏