HDU1505(最大矩形面积+DP)
来源:互联网 发布:java程序员 工作 编辑:程序博客网 时间:2024/05/07 09:02
City Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3141 Accepted Submission(s): 1298
Problem Description
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.
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.
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 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.
R – reserved unit
F – free unit
In the end of each area description there is a separating line.
Output
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.
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
对于每一行,就是求以该行为底的最大矩形的面积,
然后逐行比较求出最大值
#include<iostream>using namespace std;#define MAX 1000+20int height[MAX][MAX];int right_dis[MAX];int left_dis[MAX];int main(){ int t,n,m,i,j,temp,max; char str[4]; cin>>t; while(t--) { cin>>n>>m; memset(height,0,sizeof(height)); for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { scanf("%s",&str); //////////////求出每个位置的高度 if(str[0]=='F') height[i][j]=height[i-1][j]+1; else height[i][j]; } } max=0; for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { temp=j; while(temp>1&&height[i][j]<=height[i][temp-1]) temp=left_dis[temp-1]; left_dis[j]=temp; } for(j=m;j>=1;j--) { temp=j; while(temp<m&&height[i][j]<=height[i][temp+1]) temp=right_dis[temp+1]; right_dis[j]=temp; } for(j=1;j<=m;j++) { temp=(right_dis[j]-left_dis[j]+1)*height[i][j]; if(temp>max) max=temp; } } cout<<max*3<<endl; } return 0;}
- HDU1505(最大矩形面积+DP)
- 九度1497(最大矩形面积+DP)
- 1102 面积最大的矩形(简单DP)
- DP hdu1505 找最大矩阵
- hdu1505 City Game (最大子矩形)
- 【难】【DP】计算“skyline”下的最大矩形面积
- 51Nod Problem 1102 面积最大的矩形(DP)
- poj 1964 DP 求最大子矩形面积
- 最大矩形面积问题
- 【最大子矩形】面积
- 【最大子矩形】面积
- POJ2559 最大矩形面积
- POJ2082 最大矩形面积
- 求最大矩形面积
- 直方图最大面积矩形
- 最大矩形面积
- 最大连续矩形面积
- POJ2559 最大矩形面积
- Wireless tools for Linux 介绍 使用 交叉编译 及 移植wireless tools for liunx
- Java链接mysql
- 一 使用JavaScript
- 浅谈国家自然科学基金成功申请的方法
- 再次写给我们这些浮躁的程序员
- HDU1505(最大矩形面积+DP)
- ODBC API 开发预编译错误的解决
- uva 10167 Birthday Cake
- Json转换利器Gson之实例一-简单对象转化和带泛型的List转化
- const详解
- 整数的二进制表示中1的个数
- Big-O Cheat Sheet
- poj3250 我要做的足够 强大
- Json转换利器Gson之实例二-Gson注解和GsonBuilder