// 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. Windows Phone开发(11):常用控件(下)

    原文:Windows Phone开发(11):常用控件(下) WP控件大部分都可以从Silverlight中继承过来,这里我也只能拿一部分作演示,对于其它控件如何使用,可以参考SDK相关说明以及Sil ...

  2. 【buildroot-2011.11】You may have to install &#39;g++&#39; on your build machine

    buildroot - 2011.11 当进行交叉编译.例如像以下错误提及演示: "You may have to install 'g++' on your build machine&q ...

  3. 快速排序java

    快速排序(Quicksort)是对冒泡排序的一种改进.它是先在数组中找到一个关键数,第一趟排序将比关键数小的放在它的左边,比关键数大的放在它的右边.当第一趟排序结束后,再依次递归将左边和右边的进行排序 ...

  4. Ubuntu 13.04 用户安装 gnome 3.8 桌面

    昨天我试用了一把 Ubuntu gnome 13.04,如果你看了那一片文章:Ubuntu Gnome 13.04 体验截图.对 Ubuntu gnome 13.04 并不是采用的gnome 3.8 ...

  5. linux 文件查看目录的数

    ls -l | grep '^-'| wc -l ls -l | grep -c '^-' ls -l 输出文件夹中的文件信息的一长串(注意,文件,不同于文件,它可能是一个文件夹.联系.设备文件) g ...

  6. HDU1237 简单的计算器 【堆】+【逆波兰式】

    简单的计算器 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

  7. 移动web:转盘抽奖(幸运大转盘)

    为了获取客户.回馈客户,平台一般会推出抽奖活动类的营销页.因此web页面中,有各式各样的抽奖效果. 格子式(九宫格),背景滚动式(数字/文字/图案),旋转式(转盘),游戏式(砸蛋/拼图...).... ...

  8. Gradle 1.12 翻译——第十六章. 使用文件

    有关其它已翻译的章节请关注Github上的项目:https://github.com/msdx/gradledoc/tree/1.12,或訪问:http://gradledoc.qiniudn.com ...

  9. window.history.back()的改进方法window.history.go()

    今天在做项目时,測试人员提出了一条bug,起初没当回事,在改动过程中才意识到其重要性,故记录下来. 依照需求,系统应该实现例如以下的功能:有三个关联的页面a.aspx(简称a),b.aspx(简称b) ...

  10. oracle dblink造成远程数据库session过多

    现场报网公司数据库连不上,先检查了下数据库processes=1500,session=2200.我认为非常大啊.这个数据库没有几个人用. 查看v$session中的session最多是哪个machi ...