UVa 10074 - Take the Land

时间:2022-11-09 15:08:00

  题目大意:和UVa 836 - Largest Submatrix差不多,只需要修改一下数据就可以了。

 #include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define MAXN 110 int mat[MAXN][MAXN], sum[MAXN][MAXN]; int main()
{
#ifdef LOCAL
freopen("in", "r", stdin);
#endif
int m, n, x;
while (scanf("%d%d", &m, &n) && (m || n))
{
for (int i = ; i <= m; i++)
for (int j = ; j <= n; j++)
{
scanf("%d", &x);
if (x == ) x = ;
else if (x == ) x = -;
mat[i][j] = x;
}
memset(sum, , sizeof(sum));
for (int i = ; i <= m; i++)
for (int j = ; j <= n; j++)
sum[i][j] = mat[i][j] + sum[i-][j] + sum[i][j-] - sum[i-][j-];
int ans = ;
for (int i = ; i <= m; i++)
for (int j = ; j <= n; j++)
for (int p = i; p <= m; p++)
for (int q = j; q <= n; q++)
{
int t = sum[p][q] - sum[p][j-] - sum[i-][q] + sum[i-][j-];
ans = max(ans, t);
}
printf("%d\n", ans);
}
return ;
}

  可是还是WA了两次,一次因为还是用-1000,第二次是因为只是把前面的改成m*n矩阵,后面没改就急着提交了...唉,太粗心,太急躁了