题目大意:这个也是和UVa 836 - Largest Submatrix差不多,修改一下数据就可以套用代码的。
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 #define MAXN 110 6 7 int mat[MAXN][MAXN], sum[MAXN][MAXN]; 8 9 int main() 10 { 11 #ifdef LOCAL 12 freopen("in", "r", stdin); 13 #endif 14 int T; 15 scanf("%d", &T); 16 while (T--) 17 { 18 int n, k; 19 scanf("%d%d", &n, &k); 20 int r1, c1, r2, c2; 21 for (int i = 1; i <= n; i++) 22 for (int j = 1; j <= n; j++) 23 mat[i][j] = 1; 24 while (k--) 25 { 26 scanf("%d%d%d%d", &r1, &c1, &r2, &c2); 27 for (int i = r1; i <= r2; i++) 28 for (int j = c1; j <= c2; j++) 29 mat[i][j] = -20000; 30 } 31 memset(sum, 0, sizeof(sum)); 32 for (int i = 1; i <= n; i++) 33 for (int j = 1; j <= n; j++) 34 sum[i][j] = mat[i][j] + sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1]; 35 int ans = 0; 36 for (int i = 1; i <= n; i++) 37 for (int j = 1; j <= n; j++) 38 for (int p = i; p <= n; p++) 39 for (int q = j; q <= n; q++) 40 { 41 int t = sum[p][q] - sum[p][j-1] - sum[i-1][q] + sum[i-1][j-1]; 42 ans = max(ans, t); 43 } 44 printf("%d ", ans); 45 } 46 return 0; 47 }