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 ...
随机推荐
- struts2的异常配置
1:当我们出现异常我们浏览器会直接暴露我们的技术结构,会给我们的项目带来一些安全隐患.2:当这种错误出现,给用户感觉是非常不友好.3:怎么解决 1:如果处理找不到action方法的错误呢? 在Stru ...
- springmvc框架的搭建
1引入jar包 jar包下载地址http://maven.springframework.org/release/org/ 以下是我引入的jar包 aopalliance-1.0.jaraspectj ...
- Mysql count(1) group_concat 高级用法(count 过滤条件,group_concat过滤条件)
1.官方文档: count:COUNT(expr) [over_clause] https://dev.mysql.com/doc/refman/8.0/en/group-by-functions.h ...
- 问题解决Android studio遇到 java.lang.OutOfMemoryError: GC app:transformClassesWithDexForDebug解决方法 以及gradle优化
http://blog.csdn.net/xiaoxing0828/article/details/52242090
- leetcode 183. Customers Who Never Order
select Name as Customers from Customers where Id not in (select CustomerId from Orders);
- QT隐式数据共享
QT中许多C++类使用了隐式数据共享,最小化资源拷贝.当作为参数传递时,实际只传递了指针,这是底层完成的,程序员无需担心,即使是在多线程中,从Qt4开始: 记住,尽量使用const迭代器,vector ...
- phpcms与discuz的ucenter整合
1.安装phpcms系统,域名为pc.me 2.安装discuz,并选择安上uc_server,域名为dz.me 3.在phpcms下phpsso的系统设置 4.到ucenter管理中心- ...
- linux整合apache、php、mysql
1.打开apache配置文件,添加AddType.找到DirectoryIndex并添加index.php AddType application/x-httpd-php .php AddType a ...
- windows文件属性操作 dsofile
dsofile.dll是com组件,.net程序中引用dsofile.dll文件后,程序集名称会变成“Interop.DSOFile.dll”, com组件需要用regsvr32注册,所以需要注册ds ...
- linux下每次git clone不需输入账号密码的方法
在~/下, touch创建文件 .git-credentials, 用vim编辑此文件,输入内容格式: ame@zhenyun ~ $touch .git-credentials ame@zhenyu ...