HDU 1505 City Game(01矩阵 dp)
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.
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.
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
pid=1176" target="_blank">1176
1864pid=1003" target="_blank">1003
pid=2571" target="_blank">2571
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<stack>
using namespace std; #define N 1005 int h[N][N],le[N],ri[N];
int n,m; int main()
{
int i,t,j;
scanf("%d",&t);
while(t--)
{ memset(h,0,sizeof(h)) ;
scanf("%d%d",&n,&m);
char c;
int ans=0; for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
{ cin>>c;
if(c=='F')
h[i][j]=h[i-1][j]+1;
else
h[i][j]=0;
} for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
le[j]=j;
while(le[j]>1&&h[i][le[j]]<=h[i][le[j]-1])
le[j]=le[le[j]-1];
} for(j=m;j>=1;j--)
{
ri[j]=j;
while(ri[j]<m&&h[i][ri[j]]<=h[i][ri[j]+1])
ri[j]=ri[ri[j]+1];
} for(j=1;j<=m;j++)
ans=max(ans,h[i][j]*(ri[j]-le[j]+1));
} printf("%d\n",ans*3);
}
return 0;
}
版权声明:本文博主原创文章,博客,未经同意不得转载。
HDU 1505 City Game(01矩阵 dp)的更多相关文章
- HDU 1505 City Game (hdu1506 dp二维加强版)
F - City Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
- HDU 1505 City Game(DP)
City Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- HDU 1505 City Game【DP】
题意:是二维的1506,即在1506的基础上,再加一个for循环,即从第一行到最后一行再扫一遍--- 自己写的时候,输入的方法不对---发现输不出结果,后来看了别人的----@_@发现是将字母和空格当 ...
- HDU 6155 Subsequence Count(矩阵 + DP + 线段树)题解
题意:01串,操作1:把l r区间的0变1,1变0:操作2:求出l r区间的子序列种数 思路:设DP[i][j]为到i为止以j结尾的种数,假设j为0,那么dp[i][0] = dp[i - 1][1] ...
- HDU 2602 Bone Collector (01背包DP)
题意:给定一个体积,和一些物品的价值和体积,问你最大的价值. 析:最基础的01背包,dp[i] 表示体积 i 时最大价值. 代码如下: #pragma comment(linker, "/S ...
- HDU 1505 City Game
这题是上一题的升级版 关键在于条形图的构造,逐行处理输入的矩阵,遇到'F'则在上一次的条形图基础上再加1,遇到'R'则置为0 然后用上一题的算法,求每行对应条形图的最大矩阵的面积. 另外:本来是deb ...
- hdu 1505 City Game (hdu1506加强版)
# include <stdio.h> # include <algorithm> # include <string.h> # include <iostr ...
- hdu 4975 最大流问题解决队伍和矩阵,利用矩阵dp优化
//刚開始乱搞. //网络流求解,假设最大流=全部元素的和则有解:利用残留网络推断是否唯一, //方法有两种,第一种是深搜看看是否存在正边权的环.见上一篇4888 //至少四个点构成的环,另外一种是用 ...
- hdu 4975 最大流解决行列和求矩阵问题,用到矩阵dp优化
//刚开始乱搞. //网络流求解,如果最大流=所有元素的和则有解:利用残留网络判断是否唯一, //方法有两种,第一种是深搜看看是否存在正边权的环,见上一篇4888 //至少四个点构成的环,第二种是用矩 ...
随机推荐
- python学习笔记之八:迭代器和生成器
一. 迭代器 在前面的笔记中,已经提到过迭代器(和可迭代),这里会对此进行深入讨论.只讨论一个特殊方法---__iter__,这个方法是迭代器规则的基础. 1.1 迭代器规则 迭代的意思是重复做一些事 ...
- 重写ResultSet实现分页功能(最好的分页技术)(转)
1.首先定义一个接口Pageable 继承ResultSet这个类 并在接口中定义一些自己的方法,具体方法如下: package com.page; import java.sql.ResultSet ...
- 关于mysql主从复制的概述与分类(转)
一.概述: 按照MySQL的同步复制特点,大体上可以分为三种类别: 1.异步复制: 2.半同步复制: 3.完全同步的复制: -------------------------------------- ...
- Ceph更多Mon 更多mds
1.当前状态 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdWpfbW9zcXVpdG8=/font/5a6L5L2T/fontsize/400/fill ...
- HDU 4951 Multiplication table 阅读题
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4951 题意:给一个P进制的乘法表.行和列分别代表0~p-1,第i行第j*2+1和第j*2+2列代表的是第i ...
- android 网络运营商的名字显示规则(锁定屏幕,下拉列表)
一:Background & 有关flow MTK Operator name display分为两种类型的手机: 1. Sim卡名称: 从基于引导SIM卡读取IMSI到Spn-conf.xm ...
- 第三届蓝桥杯Java高职组决赛第三题
题目描述: 某少年宫引进了一批机器人小车.可以接受预先输入的指令,按指令行动.小车的基本动作很简单,只有3种:左转(记为L),右转(记为R),向前走若干厘米(直接记数字). 例如,我们可以对小车输入如 ...
- bootstarp modal自己主动调整宽度的JS代码
$('#ajaxPage').modal('show').css({ width: 'auto', 'margin-left': function () { return -($(this).widt ...
- CSDN 夏令营课程 项目分析
主题如以下: 正确改动后的程序: #include <iostream.h> //using namespace std; class BASE { char c; public: BAS ...
- 对于COM对象使用ComPtr代替传统指针
对于COM对象来说使用传统指针比较麻烦,还要记得Release()防止内存泄漏,一不小心就会出现各种各样的问题.针对这种问题微软提供了对于COM对象的智能指针ComPtr,这里是官方文档https:/ ...