hdu1505 City game(最大子矩阵)
来源:互联网 发布:域名被抢注怎么办 编辑:程序博客网 时间:2024/05/21 10:22
题意:
Bob打算在城市中寻找一块长方形的区域,已知城市中有些地已经被占用,要求我们帮助他选出最大的长方形区域。R代表已被占用,F代表未被占用。
分析:
这是hdu1506的升级版,即从一维变成了二维。但我们依旧可以把它转换成一维,即以每一列为一个底,算出此列中长方形的高度,然后依次按行(即按高度)dp,找出最大值。
—————>
在每一行找出当前行中第j个点向左向右延伸的最大长度,然后乘以高度即是面积。
注意最终答案要乘以3!!!!
状态转移方程:
if(h[j-1] >= h[j]) L[j] = L[j-1];
if(h[j+1] >= h[j]) R[j] = R[j-1];
具体代码:
#include <set>#include <numeric>#include <cmath>#include <queue>#include <stack>#include <vector>#include <string>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>#include <cctype>#include <string>#include <sstream>#include <map>#include <functional>using namespace std;typedef long long LL;typedef unsigned long long ULL;#define REP(idx1,num1) for(int idx1=0;idx1<(num1);idx1++)#define pb push_back#define empb emplace_back#define mp make_pair#define mem(s) memset(s,0,sizeof(s));const double EPS = 1e-6;const int maxn = 1000 + 10;int d[maxn][maxn];int l[maxn],r[maxn];int r1,c1;void debug(){ for(int i = 0; i < r1; ++i){ for(int j = 0; j < c1; ++j) cout <<d[i][j]<<" "; cout<<endl; }}int main(){ int T; scanf("%d",&T); while(T--){ scanf("%d%d",&r1,&c1); mem(d); for(int i = 0; i < r1; ++i) for(int j = 0; j < c1; ++j){ char ch;cin >> ch; //cout << ch << endl; if(ch == 'F') d[i][j] = (i == 0) ? 1 : d[i-1][j]+1; } //debug(); int max_area = 0; //从每一行开始 for(int i = 0; i < r1; ++i){ for(int j = 0; j < c1; ++j){ int t = j; while(t >= 1 && d[i][t-1] >= d[i][j]) t = l[t-1]; l[j] = t; } for(int j = c1-1; j >= 0; --j){ int t = j; while(t < c1-1 && d[i][t+1] >= d[i][j]) t = r[t+1]; r[j] = t; } /* for(int j = 0; j < c1; ++j) cout << l[j] << " "; cout << endl; */ for(int j = 0; j < c1; ++j){ int area = (r[j] - l[j] + 1) * d[i][j]; if(max_area < area) max_area = area; } } printf("%d\n",max_area*3); } return 0;}
阅读全文
0 0
- hdu1505 City Game (最大子矩阵)
- hdu1505 City game(最大子矩阵)
- hdu1505 City Game (最大子矩形)
- 【BZOJ3039】玉蟾宫/【HDU1505】【POJ1964】City Game 最大01子矩阵
- hdu1505 City Game二维01矩阵求最大矩形周长
- hdu1505(最大子矩阵)
- POJ1964 City Game(最大子矩阵)
- UVa 1330 - City Game 最大子矩阵
- poj1964 City Game(最大子矩阵)
- uva 1330City Game (最大子矩阵)
- UVA 1330 City Game(最大子矩阵)
- City Game (最大子矩阵)
- 【DP】 hdu1505 City Game
- HDU1505/POJ1964 City Game
- HDU1505--City Game
- hdu1505 City Game
- hdu1505 City Game
- 最大子矩阵,City Game,SEERC 2004,LA3029
- 自我修养
- java并发基础(四)--- 取消与中断
- php快速排序的三种实现(吊打面试官)
- Python 线程池(threadpool)
- PreparedStatement 、CallableStatement和ResultSet
- hdu1505 City game(最大子矩阵)
- redis使用心得,连接不上解决方法
- Wannafly挑战赛1 B.Xorto 两区间异或和
- 1.1Java语言发展史和平台概述
- vuejs开发音乐播放器(二):单歌手歌单列表界面
- 基于形状的模板匹配,手工绘制ROI
- VS远程调试方法总结
- oracle禁用外键关联约束
- redis(1)——Ubuntu下安装redis