#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define inf 0x3f3f3f3f
#define LL long long
using namespace std;
/************************************************
designer:hl
time:2016/11/16
Exe.Time:15 ms
Exe.Memory:1592 KB
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1081
题意:最小子矩阵
题解:矩阵压缩
************************************************/
int main() {
int n;
int num[105][105];
while (~scanf("%d", &n)) {
int a;
memset(num, 0, sizeof(num));
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) {
scanf("%d", &a);
num[i][j] = num[i][j - 1] + a;
}
int Max = -inf;
int ans = -1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
ans = -1;
for (int k = 1; k <= n; k++) {
if (ans > 0)
ans += num[k][i] - num[k][j - 1];
else
ans = num[k][i] - num[k][j - 1];
if (ans > Max)
Max = ans;
}
}
}
printf("%d\n", Max);
}
return 0;
}
hdu 1081 To The Max 矩阵压缩
最新推荐文章于 2019-09-27 19:57:58 发布