hdu 1506 dp

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstring>
#include <stack>
#include <set>
#include <map>
#include <vector>

using namespace std;
#define INF 0x2fffffff
#define LL long long
#define MAX(a,b) ((a)>(b))?(a):(b)
#define MIN(a,b) ((a)<(b))?(a):(b)
LL a[100005];
int l[100005];
int r[100005];
int main(){
    int n;
    while(scanf("%d",&n)!=EOF&&n){
        for(int i = 1;i <= n;i++)
            scanf("%d",&a[i]);
        l[1] = 1;
        for(int i = 2;i <= n;i++){
            l[i] = i;
            while(a[i] <= a[l[i]-1] && l[i] > 1){
                l[i] = l[l[i]-1];
            }
        }
        r[n]=n;
        for(int i = n-1;i >= 1;i--){
            r[i]=i;
            while(a[i] <= a[r[i] + 1] && r[i] < n){
                r[i] = r[r[i] + 1];
            }
        }
        LL ans = 0;
        for(int i = 1;i <= n;i++){
            ans  = max(ans,(r[i]-l[i]+1)*a[i]);
        }
        printf("%I64d\n",ans);
    }
    return 0;
}

注意零,注意long long

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-10 23:30:53

hdu 1506 dp的相关文章

HDU 1506 Largest Rectangle in a Histogram (dp左右处理边界的矩形问题)

E - Largest Rectangle in a Histogram Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1506 Appoint description: Description A histogram is a polygon composed of a sequence of rectangles aligned a

HDU 1506 &amp;&amp; HDU1505 &amp;&amp; HDU 2870 (DP).

~~~~ 这三道DP题是逐层递进的,大家可以从前往后做. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1506 http://acm.hdu.edu.cn/showproblem.php?pid=1505 http://acm.hdu.edu.cn/showproblem.php?pid=2870 ~~~~ 1506: 分别找每一块板子的可以的最左边界和最右边界,注意这时不能用两个for暴力(显然会TLE),所以要用DP的思想边搜边保存. 另外注

HDU 4832(DP+计数问题)

HDU 4832 Chess 思路:把行列的情况分别dp求出来,然后枚举行用几行,竖用几行,然后相乘累加起来就是答案 代码: #include <stdio.h> #include <string.h> #include <iostream> using namespace std; typedef long long ll; const ll MOD = 9999991; const int N = 1005; int t, n, m, k, x, y; ll dp1

hdu 1506

Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 10827    Accepted Submission(s): 2952 Problem Description A histogram is a polygon composed of a sequence of rect

HDU 1505 Largest Rectangle in a Histogram &amp;&amp; HDU 1506 City Game(动态规划)

1506题意:给你连续的直方图(底边边长为1),求连续的矩阵面积. 对每个直方图,分别向左向右进行扩展. #include<cstdio> #include<stdlib.h> #include<string.h> #include<string> #include<map> #include<cmath> #include<iostream> #include <queue> #include <sta

hdu 1506 Largest Rectangle in a Histogram 构造

题目链接:HDU - 1506 A histogram is a polygon composed of a sequence of rectangles aligned at a common base line. The rectangles have equal widths but may have different heights. For example, the figure on the left shows the histogram that consists of rec

hdu 3944 dp?

DP? Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 128000/128000 K (Java/Others)Total Submission(s): 1804    Accepted Submission(s): 595 Problem Description Figure 1 shows the Yang Hui Triangle. We number the row from top to bottom 0,1,2,-a

hdu 5389 dp类似背包

http://acm.hdu.edu.cn/showproblem.php?pid=5389 Problem Description Zero Escape, is a visual novel adventure video game directed by Kotaro Uchikoshi (you may hear about ever17?) and developed by Chunsoft. Stilwell is enjoying the first chapter of this

hdu 1025 dp 最长上升子序列

1 //Accepted 4372 KB 140 ms 2 //dp 最长上升子序列 nlogn 3 #include <cstdio> 4 #include <cstring> 5 #include <iostream> 6 using namespace std; 7 const int imax_n = 500005; 8 int dp[imax_n]; 9 int d[imax_n]; 10 int a[imax_n]; 11 int n; 12 int len