HDU_1505_矩阵中的最大矩形_dp
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1505
City Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6195 Accepted Submission(s): 2640
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.
R – reserved unit
F – free unit
In the end of each area description there is a separating line.
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
0
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std; char map[][];
int a[][];
int main()
{
int l[],r[];
int t,m,n;
char ch;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&m,&n);
for(int i=; i<=m; i++)
for(int j=; j<=n; j++)
cin>>map[i][j];
for(int i=; i<=m; i++)
for(int j=; j<=n; j++)
{
if(map[i][j]=='F')
a[j][i]=a[j][i-]+;
else
a[j][i]=;
}
int maxn=;
for(int i=; i<=m; i++)
{
l[]=;
r[n]=n;
for(int j=; j<=n; j++)
{
int tt=j;
while(a[tt-][i]>=a[j][i]&&tt>)
tt=l[tt-];
l[j]=tt;
}
for(int j=n-;j>=;j--)
{
int tt=j;
while(a[tt+][i]>=a[j][i]&&tt<n)
tt=r[tt+];
r[j]=tt;
}
for(int j=;j<=n;j++)
if(maxn<(r[j]-l[j]+)*a[j][i])
maxn=(r[j]-l[j]+)*a[j][i];
}
printf("%d\n",maxn*);
}
return ;
}
HDU_1505_矩阵中的最大矩形_dp的更多相关文章
- 84. Largest Rectangle in Histogram *HARD* -- 柱状图求最大面积 85. Maximal Rectangle *HARD* -- 求01矩阵中的最大矩形
1. Given n non-negative integers representing the histogram's bar height where the width of each bar ...
- hdu1506 直方图中最大的矩形 单调栈入门
hdu1506 直方图中最大的矩形 单调栈入门 直方图是由在公共基线对齐的矩形序列组成的多边形.矩形具有相同的宽度,但可能具有不同的高度.例如,左侧的数字显示了由高度为2,1,4,5,1,3,3的矩形 ...
- 19牛客暑期多校 round2 H 01矩阵内第二大矩形
题目传送门//res tp nowcoder 目的 给定n*m 01矩阵,求矩阵内第二大矩形 分析 O(nm)预处理01矩阵为n个直方图,问题转换为求n个直方图中的第二大矩形.单调栈计算,同时维护前二 ...
- [LeetCode] Kth Smallest Element in a Sorted Matrix 有序矩阵中第K小的元素
Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth ...
- [LeetCode] Longest Increasing Path in a Matrix 矩阵中的最长递增路径
Given an integer matrix, find the length of the longest increasing path. From each cell, you can eit ...
- [LeetCode] Largest Rectangle in Histogram 直方图中最大的矩形
Given n non-negative integers representing the histogram's bar height where the width of each bar is ...
- 杨氏矩阵:查找x是否在矩阵中,第K大数
参考:http://xudacheng06.blog.163.com/blog/static/4894143320127891610158/ 杨氏矩阵(Young Tableau)是一个很奇妙的数据结 ...
- 一个N*M的矩阵,找出这个矩阵中所有元素的和不小于K的面积最小的子矩阵
题目描述: 一个N*M的矩阵,找出这个矩阵中所有元素的和不小于K的面积最小的子矩阵(矩阵中元素个数为矩阵面积) 输入: 每个案例第一行三个正整数N,M<=100,表示矩阵大小,和一个整数K 接下 ...
- 如何在html中做圆角矩形和 只有右边的"分隔线"
这个网站满好的,可以常看看 css-matic中有几个很好的写css可视化的工具 其实做css 版式布局等都可以有工具的 推荐40个优秀的免费CSS工具 debugger正则表达式在线 其实是对(理论 ...
随机推荐
- IOS推断是否安装微信qq
BOOL weicaht = [[UIApplicationsharedApplication]canOpenURL:[NSURLURLWithString:@"mqqapi://" ...
- 《转》 Ceilometer项目源代码分析----ceilometer项目源代码结构分析
感谢朋友支持本博客,欢迎共同探讨交流.因为能力和时间有限,错误之处在所难免,欢迎指正! 假设转载,请保留作者信息. 博客地址:http://blog.csdn.net/gaoxingnengjisua ...
- HDU5465/BestCoder Round #56 (div.2) 二维树状数组
Clarke and puzzle 问题描述 克拉克是一名人格分裂患者.某一天,有两个克拉克(aa和bb)在玩一个方格游戏. 这个方格是一个n*mn∗m的矩阵,每个格子里有一个数c_{i, j}ci ...
- MySQL InnoDB 快速导入数据
今天把需要分析的数据导入到数据库中. 数据将近7000万条,在txt文件中存放,共5.75G.采用Load data infile 导入,最后花了18个小时导入.主要做了以下修改: 1. MySQL优 ...
- FFmpeg解码视频帧为jpg图片保存到本地
FFmpeg解码视频帧为jpg图片保存到本地 - CSDN博客 https://blog.csdn.net/qq_28284547/article/details/78151635
- sql server 生成随机数 rand函数
https://docs.microsoft.com/en-us/sql/t-sql/functions/rand-transact-sql?view=sql-server-2017 在某一个区间内生 ...
- luogu 2627 修建草坪
题目大意: 一个数列,取出一些数使得它们的总和最大且没有k个连续 思路: 首先我们可以找到一个nk的dp dp方程:dp[i]=dp[i-1]+sum[i]-sum[j] (sum[j]尽量小) 然后 ...
- P2610 [ZJOI2012]旅游 树的直径
这个题就是建图不太好建,但是我们一想,三角形貌似只能两两挨着,最后会变成一个二叉树,所以问题就变成求树的直径.建图用pair套map超级简单. 题干: 到了难得的暑假,为了庆祝小白在数学考试中取得的优 ...
- 我为什么从python转向go
应puppet大拿刘宇的邀请,我去西山居运维团队做了一个简短分享,谈谈为什么我要将我们的项目从python转向go. 坦白的讲,在一帮python用户面前讲为什么放弃python转而用go其实是一件压 ...
- POJ1389 Area of Simple Polygons 线段树
POJ1389 给定n个整数点矩形,求面积并. 显然ans必然是整数. 记录若干个事件,每个矩形的左边的竖边记为开始,右边的竖边记为结束. 进行坐标离散化后用线段树维护每个竖的区间, 就可以快速积分了 ...