hdoj 1506&&1505(City Game) dp
// 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&&1505(City Game) dp的更多相关文章
- HDOJ 1166 敌兵布阵 (线段树)
题目: Problem Description C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Ti ...
- 树链剖分+线段树 HDOJ 4897 Little Devil I(小恶魔)
题目链接 题意: 给定一棵树,每条边有黑白两种颜色,初始都是白色,现在有三种操作: 1 u v:u到v路径(最短)上的边都取成相反的颜色 2 u v:u到v路径上相邻的边都取成相反的颜色(相邻即仅有一 ...
- HDOJ题目3440 House Man(差分约束)
House Man Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 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 ...
- 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 ...
- HDOJ 1097 A hard puzzle(循环问题)
Problem Description lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius: gave a and b,how ...
- 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 ...
- HDOJ 1194 Beat the Spread!(简单题)
Problem Description Superbowl Sunday is nearly here. In order to pass the time waiting for the half- ...
- HDOJ 1698 Just a Hook (线段树)
题目: Problem Description In the game of DotA, Pudge’s meat hook is actually the most horrible thing f ...
随机推荐
- 採用Android中的httpclient框架发送post请求
/** * 採用httpclientPost请求的方式 * * @param username * @param password * @return null表示求得的路径有问题,text返回请求得 ...
- 【原创】poj ----- 1182 食物链 解题报告
题目地址: http://poj.org/problem?id=1182 题目内容: 食物链 Time Limit: 1000MS Memory Limit: 10000K Total Submi ...
- Android规范发展
一.Android 编码规范 1.java 代码中不出现中文.最多凝视中能够出现中文 2.局部变量命名.静态成员变量命名 仅仅能包括字母,单词首字母出第一个外,都为大写,其它字母都为小写 3.常量命名 ...
- sql查询 数据库 表 字段 等
1.查询数据库中的所有数据库名: SELECT Name FROM Master..SysDatabases ORDER BY Name 2.查询某个数据库中所有的表名: SELECT Name FR ...
- div 浮动框
- C++ string类取字符串的左右子串(以特定子串为分界限)
// Example3.cpp : 定义控制台应用程序的入口点. //以特定单词为分界,求取字符串的左右子串 #include "StdAfx.h" #include <st ...
- 【原创】纯OO:从设计到编码写一个FlappyBird (一)
说起来,自学计算机也有2年多的时间了,自己还没有从设计到编码,完完整整的设计一个基于面向对象的软件的经历..囧 于是,就有了这个系列.首先选用的语言是Java,没别的原因,HeadFirst设计模式是 ...
- SICP 锻炼 (2.15)解决摘要:深入思考间隔误差
SICP 2.15 是接着 题目 2.14 的, 题目 2.14中提到了Alyssa设计的区间计算模块在并联电阻计算时会出现故障,这个问题是Lem发现的. 接着,一个叫Eva的人也发现了这个问题.同一 ...
- 桥模式设计模式进入Bridge
Abstraction:抽象部分的父类,定义须要实现的接口. 维护对实现部分的引用,从而把实现桥接到Implementor中去 Implementor:实现部分的接口 RefinedAbstracti ...
- 经excel要将数据库(ORACLE)要插入数据
大家都知道PL/SQL可以excel数据复制.我们也可以通过相同excel将数据插入到数据库. 下面我们就来简单的样品,并与主题演示 首先,我们创建了一个表test CREATE TABLE test ...