City game
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 4531 accepted submission (s): 1919
Problem descriptionbob is a strategy game programming specialist. in his new city building game the gaming environment is as follows: a city is built up by areas, in which there are streets, trees, factories and buildings. there is still some space in the area that is unoccupied. the strategic task of his game is to win as much rent money from these free spaces. to win rent money you must erect buildings, that can only be rectangular, as long and wide as you can. bob is trying to find a way to build the biggest possible building in each area. but he comes into SS some problems-he is not allowed to destroy already existing buildings, trees, factories and streets in the area he is building in.
Each area has its width and length. The area is divided into a grid of equal square units. The rent paid for each unit on which you're building stands is 3 $.
Your task is to help Bob solve this problem. the whole city is divided into k areas. each one of the areas is 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.
Inputthe first line of the input contains an integer k-determining the number of datasets. next lines contain the area descriptions. one description is defined in the following way: the first line contains two integers-area length m <= 1000 and width n <= 1000, separated by a blank space. 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.
Outputfor each data set in the input print on a separate line, on the standard output, the integer that represents the profit obtained by erecting the largest building in the Area encoded by the data set.
Sample Input
25 6R F F F F FF F F F F FR R R F F FF F F F F FF F F F F F5 5R R R R RR R R R RR R R R RR R R R RR R R R R
Sample output
450
Sourcesoutheastern Europe 2004
The upgraded version of 1506 is only one-dimensional H. You need to calculate the details and read the previous article.
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int N = 1005;int mat[N][N], le[N][N], ri[N][N], h[N][N], cas, n, m;int main(){ char s[5]; scanf ("%d", &cas); while (cas--) { memset (mat, 0, sizeof (mat)); memset (h, 0, sizeof (h)); scanf ("%d%d", &n, &m); for (int i = 1; i <= n; ++i) { h[i][0] = h[i][m + 1] = -1; for (int j = 1; j <= m; ++j) { scanf ("%s", s), mat[i][j] = s[0]; le[i][j] = ri[i][j] = j; if (mat[i][j] == 'F') h[i][j] = h[i - 1][j] + 1; } } int ans = 0; for (int i = 1; i <= n; ++i) { for (int j = m; j >= 1; --j) while (h[i][ri[i][j] + 1] >= h[i][j]) ri[i][j] = ri[i][ri[i][j] + 1]; for (int j = 1; j <= m; ++j) { while (h[i][le[i][j] - 1] >= h[i][j]) le[i][j] = le[i][le[i][j] - 1]; ans = max (ans, (ri[i][j] - le[i][j] + 1) * h[i][j]); } } printf ("%d\n", ans * 3); } return 0;}