hdu 1505,1506
1506题目
1505题目
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
const int Max = 100010;
int main()
{
int n;
long long num[Max],temp;
int L[Max],R[Max];
while(~scanf("%d",&n),n)
{
memset(L,0,sizeof( L));
memset(R,0,sizeof(R));
for(int i=1; i<=n; i++)
scanf("%lld",&num[i]);
L[1] = 1;
R[n] = n;
for(int i=2; i<=n; i++)
{
temp = i;
while( temp > 1 && num[i]<=num[temp-1])
temp = L[temp-1];
L[i] = temp;
}
for(int i=n-1; i>=1; i--)
{
temp = i;
while(temp < n && num[i] <= num[temp+1])
temp = R[temp+1];
R[i] = temp ;
}
long long max = 0;
for(int i=1; i<= n; i++)
{
if((R[i]-L[i]+1)*num[i] > max ) max = (R[i]-L[i]+1)*num[i];
}
printf("%lld\n",max);
}
return 0;
}
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int d[1010][1010],L[1010],R[1010];
int main()
{
int n,T,m;
char ch[2];
cin>>T;
while(T--)
{
memset(d,0,sizeof(d));
cin>>n>>m;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m; j++)
{
cin>>ch;
if(ch[0]=='F')
d[i][j]=d[i-1][j] + 1;
else
d[i][j] = 0;
}
}
int max = 0;
for(int i=1; i<=n; i++)
{
for(int j=1; j<= m; j++ )
{
L[j] = j;
while(L[j]>1 && d[i][j] <= d[i][L[j]-1] )
L[j] = L[ L[j] - 1 ];
}
for(int j=m; j>=1; j--)
{
R[j] = j;
while(R[j] < m && d[i][j] <= d[i][R[j] + 1]){
R[j] = R[ R[j] + 1];
}
}
for(int j=1; j<=m; j++)
{
if(max < ((R[j]-L[j]+1)*d[i][j]))
max = ( R[j]-L[j]+1)*d[i][j];
}
}
cout<<max*3 <<endl;
}
return 0;
}
这两道题差不多,第一道题相对于第二道来说是一维的,第二道相对于第一道来说是二维的。
hdu 1505,1506的更多相关文章
- HDU 1505 City Game (hdu1506 dp二维加强版)
F - City Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
- HDU 1505 Largest Rectangle in a Histogram && HDU 1506 City Game(动态规划)
1506意甲冠军:给你一个连续的直方图(拼贴底部长度1).求连续基质区. 对每一个直方图,分别向左向右进行扩展. #include<cstdio> #include<stdlib.h ...
- HDU——T 1506 Largest Rectangle in a Histogram|| POJ——T 2559 Largest Rectangle in a Histogram
http://acm.hdu.edu.cn/showproblem.php?pid=1506 || http://poj.org/problem?id=2559 Time Limit: 2000/1 ...
- hdu 1505(dp求最大子矩阵)
题意:就是让你求出全由F组成的最大子矩阵. 分析:这是hdu 1506的加强版,只不过这道题变成了2维的,那我们就一行一行的来.具体的分析见1506的博客:http://www.cnblogs.com ...
- hdu 1505 && hdu1506 &&hdu 2830 && 2870 总结---------DP之状图选最大矩形
/* 多谢了“闭眼,睁眼” 同学给我一套dp专题,不然真是没接触过这种题型. 做个4个简单的,很高兴有所收获. 2013-08-06 /* HDU 1506 最基础的一道题目,其主要精髓就在于两个数组 ...
- POJ 1964&HDU 1505&HOJ 1644 City Game(最大0,1子矩阵和总结)
最大01子矩阵和,就是一个矩阵的元素不是0就是1,然后求最大的子矩阵,子矩阵里的元素都是相同的. 这个题目,三个oj有不同的要求,hoj的要求是5s,poj是3秒,hdu是1秒.不同的要求就对应不同的 ...
- 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 1505 City Game
这题是上一题的升级版 关键在于条形图的构造,逐行处理输入的矩阵,遇到'F'则在上一次的条形图基础上再加1,遇到'R'则置为0 然后用上一题的算法,求每行对应条形图的最大矩阵的面积. 另外:本来是deb ...
随机推荐
- How to read very large text files fast
Question Does anyone know the fastest way to read large text files (10Mb) into a string.Readln is ju ...
- cmd dos bat 深度变量文件夹指定文件
echo off ::指定起始文件夹 :: 指定文件夹 set DIR = abc :: d:/abc 改脚本放在d: set DIR="%cd%" echo DIR=%DIR% ...
- windows本地blast
详细可参考https://www.jianshu.com/p/2f125cdf8262:https://blog.csdn.net/qq_34296043/article/details/544277 ...
- mydqldump
[mydqldump] One way to create a snapshot of the data in an existing master database is to use the my ...
- ie6浏览器的安装
试过各种方法都不行,最后用ie8卸载工具,不仅卸载了ie8还自动安装了ie6,非常棒!!!我的空间有那款卸载工具.
- Spring的属性注入, byName和byType还有注入List属性
昨天花了一晚上的时间又仔细研究了一下Spring的属性注入, 一个新的方法: 自动装载和autowire, 不过因为又想起来老师说不常用, 感觉这一晚上的时间有点亏, 还是自己太愚钝了, 反应太慢 先 ...
- 一些常用的c++系统函数
数学<cmath><math.h>: 1 三角函数 double sin (double); double cos (double); double tan (double); ...
- 45. Jump Game II (Array; Two-Pointers,Greedy)
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- Mac下MySQL卸载方法
mac下mysql的DMG格式安装内有安装文件,却没有卸载文件……很郁闷的事.1 sudo rm /usr/local/mysql2 sudo rm -rf /usr/local/mysql*3 su ...
- 【Python基础教程第2版】——第一讲:基础知识
1.长字符串:(用三引号如'''或者"""来引起来) >>> print """This is a very log st ...