1330-city Game
Time limit:3.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=460&page=show_ problem&problem=4076
Bob is a strategy game programming specialist. In He new city building game the gaming environment are as Follows:a City are built up by areas, in which there are s, trees, factories and buildings. There is still some spaces in the "area" is unoccupied. The strategic task of the game is to win as much rent as this free spaces. To win rent money for you must erect buildings, which can only is rectangular, as long and wide as you can. Bob is trying to find a way to build the biggest possible building into each area. But He comes across some problems:he are not allowed to destroy already, existing, buildings, trees and factories In the [area] building in.
Each area has its width and length. The area was divided into a grid of equal square units. The rent paid for each of which you ' re building stands is 3$.
Your task is to help Bob solve this problem. The whole city are divided into K areas. Each one of the areas are rectangular and has a different grid size with its own length M and width N. The existing occupied units are marked with the symbol R. The unoccupied units are marked with the symbol F.
Input
The ' the ' input file contains an integer k:determining the number of datasets. Next lines contain the area descriptions. One description is defined in the following way:the A/contains two Integers-area length m<=1000 and width n&l t;=1000, separated by a blank. The next M lines contain N symbols that mark the reserved or free grid units, separated by a blank space. The symbols used are:
r:reserved Unit F:free Unit
In the ' end ' of each area description there is a separating line.
Output
This article URL address: http://www.bianceng.cn/Programming/sjjg/201410/45431.htm
For each data set in the input file print on a separate line, on the standard output, the integer that represents the Prof The IT obtained by erecting the largest building into the area encoded by the data set.
Sample Input
2
5 6 R F F F F. F F F F. F F. F F. F F R R R F F F. F F f f F F. F. (E) "F." E "E", "E", "E", "E", "I", "
5
," f R/R R R R R R R R R R R R-R r R
Sample Output
0
This question is a two-dimensional extension of the POJ 2559/hdu 1506 largest Rectangle in a histogram.
Ideas please refer to this article.
Complete code:
/*0.072s*/#include <cstdio> #include <algorithm> using namespace std;
const int MAXN = 1000;
int MAT[MAXN][MAXN], UP[MAXN][MAXN], LEFT[MAXN][MAXN], RIGHT[MAXN][MAXN];
int main () {int T;
scanf ("%d", &t);
while (t--) {int m, n;
scanf ("%d%d", &m, &n); for (int i = 0; i < m. i++) for (int j = 0; J < N; j +) {int ch = get
char ();
while (Ch!= ' F ' && ch!= ' R ') ch = getchar (); MAT[I][J] = ch = = ' F '?
0:1;
int ans = 0;
for (int i = 0; i < m i++)//from top to bottom line by row {int lo =-1, ro = n;
for (int j = 0; J < N; j +) scan from left to right, maintain up and ieft if (Mat[i][j]) {
UP[I][J] = Left[i][j] = 0;
Lo = j;
} else {Up[i][j] = (i = = 0 1:up[i-1][j] + 1);
LEFT[I][J] = (i = = 0? lo + 1:max (left[i-1][j), lo + 1));
for (int j = n-1 J >= 0; j--)/right-to-left Scan, maintain right and update answer if (MAT[I][J))
{Right[i][j] = n;
ro = j; else {Right[i][j] = (i = = 0? ro-1: Min (right[i-1][j), RO
-1));
ans = max (ans, up[i][j] * (Right[i][j]-left[i][j] + 1));
} printf ("%d\n", ans * 3);
return 0; }