HDU 1505 City Game (hdu1506 dp Two-dimensional enhanced version)

Source: Internet
Author: User

f-city GameTime limit:1000MS Memory Limit:32768KB 64bit IO Format:%i64d &%i6 4u Submit Status Practice HDU 1505Appoint Description:

Description

Bob is a strategy game programming specialist. In He new city building game the gaming environment was as Follows:a City was built up by areas, in which there was street S, trees,factories and buildings. There is still some space in the area it is unoccupied. The strategic task of his game was to win as much rent money from these free spaces. To win rent-must erect buildings, that can is only being rectangular, as long and wide as you can. Bob is trying to find a by-build the biggest possible building in each area. But he comes across some problems? He is not allowed to destroy already existing buildings, trees, factories and streets in the area he's building in.

Each of the area have its width and length. The area was divided into a grid of equal square units. The rent paid for each unit on which you ' re building stands are 3$.

Your task is to help Bob solve this problem. The whole city was divided into K areas. Each one of the areas is rectangular and have a different grid size with its own length M and width n.the existing occupied Units is marked with the symbol R. The unoccupied units is marked with the symbol F.

Input

The 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 both Integers-area length m<=1000 and width n&l t;=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 is:

R? Reserved unit

F? Free Unit

The end of each area description there are a separating line.

Output

For each data set with the input print on a separate line, on the standard output, the integer that represents the profit OB tained by erecting the largest building, the area encoded by the data set.

Sample Input

Sample Output

45 0
#include <stdio.h>#include<string.h>#include<iostream>#include<algorithm>using namespacestd;intd[1010][1010];intl[1010];intr[1010];intMain () {intN; CIN>>N;  while(n--)    {        intb; CIN>>a>>b; //memset (d,0,sizeof (d));         for(intI=0; i<a; i++)        {             for(intj=0; j<b; J + +)            {                Charc[2]; CIN>>C; if(c[0]=='F') D[i][j]=1; ElseD[i][j]=0; }        }        /*0 1 1 1 1 1 0 1 1 1 1 each 1 1 1 1 1 (f=1,r=0, easy to sum) 1 2 2 2 2 20 0 0 1 1 1 after the conversion is the right matrix 0                   0 0 3 3 31 1 1 1 1 1 1 1 1 4 4 41 1 1 1 1 1 2 2 2 5 5 5 */         for(intI=1; i<a; i++)        {             for(intj=0; j<b; J + +)            {                if(d[i][j]!=0) D[i][j]=d[i-1][j]+1; }        }     /*printf ("--------------->\n");            for (int. i=0; i<a; i++) {for (int j=0; j<b; j + +) printf ("%d", d[i][j]);        printf ("\ n"); } printf ("----------------->\n");*/        intmax=0;  for(intI=0; i<a; i++){             for(intj=0; j<b; J + +) {L[j]=J;  while(l[j]>0&&d[i][l[j]-1]>=D[i][j]) l[j]=l[l[j]-1]; }             for(intj=b-1; j>-1; j--) {R[j]=J;  while(r[j]<b-1&&d[i][r[j]+1]>=D[i][j]) r[j]=r[r[j]+1]; }             for(intj=0; j<b; J + +)                if(max< (r[j]-l[j]+1)*D[i][j])) Max= ((r[j]-l[j]+1)*D[i][j]); } cout<<max*3<<Endl; }    return 0;}

HDU 1505 City Game (hdu1506 dp Two-dimensional enhanced version)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.