// l表示从l[i]到i连续大于a[i]的最远左区间。r表示从i到r[i]连续大于a[i]的最远又区间

DP 找出 a[i] 的最远左区间和最远右区间与自己连着的比自己大的数的长度 , 然后用这个长度乘以 a[i], 乘积最大的那个就是答案

hdoj 1506

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define N 100000+10
#define INF 0xfffffff
#define ll __int64
ll Max(ll x,ll y)
{
if(x>y)
return x;
return y;
}
ll r[N],l[N];
ll a[N];
int main()
{
ll n;
while(scanf("%I64d",&n),n)
{
for(int i=1;i<=n;i++)
scanf("%I64d",&a[i]);
a[0]=a[n+1]=-INF;
l[0]=r[n+1]=0;
for(int i=1;i<=n;i++)
{ l[i]=i;
while(a[l[i]-1]>=a[i])
l[i]=l[l[i]-1]; }
for(int i=n;i>=1;i--)
{ r[i]=i;
while(a[r[i]+1]>=a[i])
r[i]=r[r[i]+1]; }
ll maxn=0;
for(int i=1;i<=n;i++)
{
maxn=Max((r[i]-l[i]+1)*a[i],maxn);
}
printf("%I64d\n",maxn);
}
return 0;
}

hdoj 1505是1506的加强版,对于矩阵的每一行採取相同的操作

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define N 1000+10
char a[N][N];
int dp[N][N];
int r[N],l[N];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,m;
int maxn=0;
scanf("%d%d",&n,&m);
memset(dp,0,sizeof(dp));
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
scanf(" %c",&a[i][j]);
if(a[i][j]=='R')
dp[i][j]=0;
else
dp[i][j]=dp[i-1][j]+1;
}
} for(int i=1;i<=n;i++)
{
dp[i][0]=dp[i][m+1]=-1;
l[0]=r[m+1]=0;
for(int j=1;j<=m;j++)
{
l[j]=j;
while(dp[i][l[j]-1]>=dp[i][j])
l[j]=l[l[j]-1];
}
for(int j=m;j>=1;j--)
{ r[j]=j;
while(dp[i][r[j]+1]>=dp[i][j])
r[j]=r[r[j]+1]; }
for(int j=1;j<=m;j++)
{
maxn=max(maxn,(r[j]-l[j]+1)*3*dp[i][j]);
} }
printf("%d\n",maxn);
}
return 0;
}

hdoj 1506&amp;&amp;1505(City Game) dp的更多相关文章

  1. HDOJ 1166 敌兵布阵 (线段树)

    题目: Problem Description C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Ti ...

  2. 树链剖分+线段树 HDOJ 4897 Little Devil I(小恶魔)

    题目链接 题意: 给定一棵树,每条边有黑白两种颜色,初始都是白色,现在有三种操作: 1 u v:u到v路径(最短)上的边都取成相反的颜色 2 u v:u到v路径上相邻的边都取成相反的颜色(相邻即仅有一 ...

  3. HDOJ题目3440 House Man(差分约束)

    House Man Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  4. HDOJ 2114 Calculate S(n)(找周期)

    Problem Description Calculate S(n). S(n)=1^3+2^3 +3^3 +--+n^3 . Input Each line will contain one int ...

  5. HDOJ 2117 Just a Numble(模拟除法)

    Problem Description Now give you two integers n m, you just tell me the m-th number after radix poin ...

  6. HDOJ 1097 A hard puzzle(循环问题)

    Problem Description lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius: gave a and b,how ...

  7. HDOJ 1076 An Easy Task(闰年计算)

    Problem Description Ignatius was born in a leap year, so he want to know when he could hold his birt ...

  8. HDOJ 1194 Beat the Spread!(简单题)

    Problem Description Superbowl Sunday is nearly here. In order to pass the time waiting for the half- ...

  9. HDOJ 1698 Just a Hook (线段树)

    题目: Problem Description In the game of DotA, Pudge’s meat hook is actually the most horrible thing f ...

随机推荐

  1. ORACLE 中的 锁 介绍

    ORACLE 中的 锁 介绍 Oracle数据库支持多个用户同时与数据库进行交互,每个用户都可以同时运行自己的事务,从而也需要对并发访问进行控制.Oracle也是用“锁”的机制来防止各个事务之间的相互 ...

  2. 很久没来这里,今天的评测java怪东西,左右Date类和时间戳转换

    在发展过程中,经常会遇到利用上课时间.说话的Date类就不得不提时间戳,左右fr=aladdin" target="_blank">的定义大家能够看看网上对时间戳的 ...

  3. 【Quick-COCOS2D-X 3.3 怎样绑定自己定义类至Lua之三】动手绑定自己定义类至Lua

        查看[Quick-COCOS2D-X 3.3 怎样绑定自己定义类至Lua之二]新建项目中配制环境,我们完美的在新建项目中完毕了绑定须要的环境,接下来才是最关健的一步.绑定自己定义C++类至Lu ...

  4. Mongoose即使是简单的表查询

    从我原来的博客尖,欢迎大家光临 http://www.hacke2.cn 像我这篇文章所说的基于Node.js + jade + Mongoose 模仿gokk.tv.当时停止开发是由于我深深的感觉到 ...

  5. 【原创】ZOJ_1649 Rescue 解题报告

    Rescue Time Limit: 2 Seconds      Memory Limit: 65536 KB Angel was caught by the MOLIGPY! He was put ...

  6. 返璞归真 asp.net mvc (10) - asp.net mvc 4.0 新特性之 Web API

    原文:返璞归真 asp.net mvc (10) - asp.net mvc 4.0 新特性之 Web API [索引页][源码下载] 返璞归真 asp.net mvc (10) - asp.net ...

  7. mysqlbackup 还原特定的表

    mysqlbackup使用TTS恢复指定表. ************************************************************* 4.恢复特定表 ******* ...

  8. POJ 2352 Stars 树阵

    标题效果:特定y值在升序一些点.一个点的定义level值点的数目对于其左下,每个请求level多少分. 思维:因为y值它是按升序.所以分的差距仅仅是推断x值相比之前的大.就用树状数组维护. CODE: ...

  9. Linux 于 shell 变数 $#,$@,$0,$1,$2 含义解释:

    变量说明: $$ Shell自己PID(ProcessID) $! Shell背景上次执行Process的PID $? 命令的结束代码(返回值) $- 使用Set命令设定的Flag一览 $* 全部參数 ...

  10. 翻译器DIY————次序

    突然有一种冲动,想要写一个编译器. 因此,检查在网上搜索相关信息,思想direct3D 有本书叫龙,也有个龙书 Compilers Principles,Techniques, & Tool ...