// 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. WPS2012交叉引用提示word比wps这种强烈的更新参考

                WPS2012交叉引用技巧,word比wps这点强更新參考文献 到时生成仅仅有有一条线,好像WPS不能够,word能够,假设谁知道能够补充.^_^ 1.写论文,參考文献的改动非 ...

  2. 设计模式(一)工厂模式Factory(创建类型)

    设计模式一 工厂模式Factory 在面向对象编程中, 最通常的方法是一个new操作符产生一个对象实例,new操作符就是用来构造对象实例的.可是在一些情况下, new操作符直接生成对象会带来一些问题. ...

  3. leetcode先刷_Remove Duplicates from Sorted List II

    删除重复节点列表中的.假设所有val如果仅仅是为了保持一个非常easy.应承担重复val节点被删除话.要保持pre节点.每当你想保存这pre问题节点,应该head节点可以被取出,好了,没问题边境控制. ...

  4. 重新想象 Windows 8 Store Apps (14) - 控件 UI: RenderTransform, Projection, Clip, UseLayoutRounding

    原文:重新想象 Windows 8 Store Apps (14) - 控件 UI: RenderTransform, Projection, Clip, UseLayoutRounding [源码下 ...

  5. 说说UI设计

    近期的项目验收中,无数次的提到了UI的设计,首先来说说为什么UI设计如此重要. 对于用户来说产品的外观是最先映入眼帘的,无论你用了什么高端的技术,无论你后台代码封装的多么好,用户是无法体会到的,能体会 ...

  6. opencv环境的搭建,并打开一个本地PC摄像头。

    1.opencv环境结构 推荐连结 http://www.cnblogs.com/Anykong/archive/2011/04/06/Anykong_OpenCV1.html 2.以下是基本測试,和 ...

  7. UBUNTU12.04下安装配置体验gnome3

    年. ubuntu12.04默认采用unity界面,但是自己更加喜欢gnome3的操作方式. 安装gnome3: sudo apt-get install  gnome-shell 其实安装成功后,注 ...

  8. C++ 版本的split_string

    vector<string> split_string(const string &in, char del, bool skip_empty) { vector<strin ...

  9. poj2386Lake Counting

    题意是这种.给你一个N*M的矩形图.这个图由两个东西组成.'.'和'W', W代表这个地方有水. .代表这个地方没水. 假设一个有水的地方它的上下左右,左上,坐下.右上.右下也有水,那么 就看成它们连 ...

  10. NOI 评价体系 arbiter 安装方法 常见的问题 移植

    #!/bin/bash AppPath="$PWD"   读取当前文件夹 echo "Arbiter is installing..." sudo apt-ge ...