题目大意:给出一张地图,求出这张地图中最大的子矩阵,使得这个子矩阵不包含字母‘R’。
思路:简单的悬线法求最大子矩阵,还是不带权值的,很好求。好久没写悬线了,复习一下。
CODE:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define MAX 1010 using namespace std; int m,n; bool map[MAX][MAX]; int max_left[MAX][MAX],max_right[MAX][MAX]; int max_up[MAX][MAX]; inline char GetChar() { char c; while(c = getchar(),c == ' ' || c == '\n' || c == '\t' || c == '\r'); return c; } int main() { cin >> m >> n; for(int i = 1; i <= m; ++i) for(int j = 1; j <= n; ++j) map[i][j] = GetChar() == 'F'; for(int i = 1; i <= m; ++i) { for(int j = 1; j <= n; ++j) max_left[i][j] = !map[i][j] ? 0:max_left[i][j - 1] + 1; for(int j = n; j; --j) max_right[i][j] = !map[i][j] ? 0:max_right[i][j + 1] + 1; } for(int i = 1; i <= m; ++i) for(int j = 1; j <= n; ++j) if(map[i][j] && map[i - 1][j]) { max_up[i][j] = max_up[i - 1][j] + 1; max_left[i][j] = min(max_left[i][j],max_left[i - 1][j]); max_right[i][j] = min(max_right[i][j],max_right[i - 1][j]); } int ans = 0; for(int i = 1; i <= m; ++i) for(int j = 1; j <= n; ++j) ans = max(ans,(max_left[i][j] + max_right[i][j] - 1) * (max_up[i][j] + 1)); cout << ans * 3 << endl; return 0; }
原文地址:http://blog.csdn.net/jiangyuze831/article/details/41551925