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正则表达式在线 其实是对(理论 ...
随机推荐
- react 项目实战(四)组件化表单/表单控件 高阶组件
高阶组件:formProvider 高阶组件就是返回组件的组件(函数) 为什么要通过一个组件去返回另一个组件? 使用高阶组件可以在不修改原组件代码的情况下,修改原组件的行为或增强功能. 我们现在已经有 ...
- Myeclipse的优化方法
近期在实习,公司给分配了新的电脑,可是不知道怎么弄得,总是弄得非常卡,没办法仅仅有自己好好整理一下电脑了,另外.为了提高编程的效率.顺便也把Myeclipse也优化了一下. 第一步: 取消自己主动va ...
- SpringMVC 学习笔记(五) 基于RESTful的CRUD
1.1. 概述 当提交的表单带有_method字段时,通过HiddenHttpMethodFilter 将 POST 请求转换成 DELETE.PUT请求,加上@PathVariable注解从而实现 ...
- Android Java包各种功能简述
开发Android应用程序基本上使用的都是Java语言. 那么要想灵活的应用这一系统,就应当熟悉当中的Android Java包的各种功能. 一般的JAVA应用中.假设需用引用基础类库,通常须要使用例 ...
- ZOJ 3872 计算对答案的贡献
D - Beauty of Array Description Edward has an array A ...
- Android6.0源码分析之录音功能(一)【转】
本文转载自:http://blog.csdn.net/zrf1335348191/article/details/54949549 从现在开始一周时间研究录音,下周出来一个完整的博客,监督,激励!!! ...
- Ubuntu下Zabbix服务器监控工具部署
Ubuntu下Zabbix服务器监控工具部署 一 安装安装Apache.Mysql.Php.zabbix sudo apt-get update sudo apt-get install apache ...
- 【Poj3126】【BNUOJ3245】Prime Path
http://poj.org/problem?id=3126 https://www.bnuoj.com/v3/problem_show.php?pid=3245 题目鬼图 刚开始看到题目的图觉得这题 ...
- 【转】Material Design 折叠效果 Toolbar CollapsingToolbarLayout AppBarLayout
我非常喜欢Material Design里折叠工具栏的效果,bilibili Android客户端视频详情页就是采用的这种设计.这篇文章的第二部分我们就通过简单的模仿bilibili视频详情页的实现来 ...
- E20170606-gg
complete adj. 完整的; 完成的; (用以强调) 完全的; 达到结尾的; vt. 完成,使完满; 完成或结束; 填写(表格); process n. 过程; 工序; 做事方法; 工艺 ...