2013
11-10

# City Game

Bob 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 across 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.

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 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.

For 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.

2
5 6
R F F F F F
F F F F F F
R R R F F F
F F F F F F
F F F F F F

5 5
R R R R R
R R R R R
R R R R R
R R R R R
R R R R R

45
0

//* @author  [email protected]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
int[][] N=new int[1001][1001];
int[][] M=new int[1001][1001];
int k=scan.nextInt();
int n=0,m=0,d,maxA;
for(int z=0;z< k;z++){
maxA=0;
m=scan.nextInt();
n=scan.nextInt();
for(int i=0;i< m;i++)
for(int j=0;j< n;j++)
if(scan.next().equals("F"))
M[i][j]=N[i][j]=1; else M[i][j]=N[i][j]=0;
for(int i=0;i< m;i++) for(int j=n-2;j>=0;j--) if(N[i][j]!=0)N[i][j]+=N[i][j+1];
for(int i=0;i< n;i++) for(int j=m-2;j>=0;j--) if(M[j][i]!=0)M[j][i]+=M[j+1][i];
for(int i=0;i< m;i++)
for(int j=0;j< n;j++){
d=N[i][j];
for(int l=0;l< M[i][j];l++){
if(N[i+l][j]< d)d=N[i+l][j];
if(d*(l+1)>maxA)maxA=d*(l+1);
}
}
System.out.println(maxA*3);
}
}
}

1. for(int i=1; i<=m; i++){
for(int j=1; j<=n; j++){
dp = dp [j-1] + 1;
if(s1.charAt(i-1) == s3.charAt(i+j-1))
dp = dp[i-1] + 1;
if(s2.charAt(j-1) == s3.charAt(i+j-1))
dp = Math.max(dp [j - 1] + 1, dp );
}
}
这里的代码似乎有点问题？ dp(i)(j) = dp(i)(j-1) + 1;这个例子System.out.println(ils.isInterleave("aa","dbbca", "aadbbcb"));返回的应该是false

2. 学算法中的数据结构学到一定程度会乐此不疲的，比如其中的2－3树，类似的红黑树，我甚至可以自己写个逻辑文件系统结构来。

3. 第23行：
hash = -1是否应该改成hash[s ] = -1

因为是要把从字符串s的start位到当前位在hash中重置

修改提交后能accept，但是不修改居然也能accept