hdu1505city game dp
来源:互联网 发布:汽车配件管理销售软件 编辑:程序博客网 时间:2024/06/06 18:57
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
这个题果然是1506的升级版 又是一阵冥思苦想
看来数据还不是特别大 要按我之前的想法做就对了 就是截止到某行处理好连续喝间断
#include <iostream>#include<cstring>#include<cstdio>using namespace std;char a[1005];int r[1005],l[1005],num[1005][1005];int n,m,t;int main(){ //freopen("cin.txt","r",stdin); scanf("%d",&t); while(t--) { scanf("%d%d",&m,&n); memset(num,0,sizeof(num)); for(int i=1;i<=m;i++) { for(int j=0;j<n;j++) { scanf("%s",a);//scanf("%c",&a[i][j]); if(a[0]=='F') num[i][j+1]=1+num[i-1][j+1]; else num[i][j+1]=0; } //getchar(); } int maxn=-1,tmp,t; for(int i=1;i<=m;i++) { for(int j=1;j<=n;j++) l[j]=j,r[j]=j; // l[1]=1,r[n]=n; num[i][0]=num[i][n+1]=-1; for(int j=2;j<=n;j++) { //t=j; while(num[i][j]<=num[i][l[j]-1]) l[j]=l[l[j]-1]; } for(int j=n-1;j>=1;j--) { // t=j; while(num[i][j]<=num[i][r[j]+1]) r[j]=r[r[j]+1]; } for(int j=1;j<=m;j++) { tmp=num[i][j]*(r[j]-l[j]+1); if(maxn<tmp) maxn=tmp; } } printf("%d\n",maxn*3); } return 0;}
0 0
- hdu1505city game dp
- 单调栈优化dp:hdu1506Largest Rectangle in a Histogram &hdu1505city game dp ||附面试题:柱子围水|柱子围面积
- 【DP】 hdu1505 City Game
- LA_3029City Game( DP )
- Hdu 4701 Game -- DP
- hdu1054Strategic Game(树形DP)
- ZOJ_3791_An Easy Game(DP)
- 树形dp Strategic game
- zoj1134 Strategic Game dp
- [DP]Play Game
- [HDU 4701 Game] DP
- 【Leetcode】Jump Game (DP)
- Strategic game(树形DP)
- DP Jump Game
- hdu 5218 Game (dp)
- dp- hdu 5218Game
- sgu273:Game Po(dp)
- DP------Jump Game
- IMX6Solo启动流程-Linux 内核启动 一
- DataGridView和ListView比较
- Eclipse中Tomcat插件的使用说明
- 分冶法之归并排序
- Asynchttpclient的使用及请求与响应封装
- hdu1505city game dp
- 凌凯短信Webservice接口报错解决办法
- system() 函数执行遇到 Cannot allocate memory
- 用cxf编写基于spring的webservice之上篇
- C++学习之如何理解*&,即指针的引用
- UE设置
- Android onMeasure()
- [教程] Jsmooth打包Jar生成exe文件,实现不装Java环境运行
- 自定义UIActionSheet的颜色IOS8前后的区别