Problem description
| Question number: |
201312-3 |
| Question Name: |
The largest rectangle |
| Time limit: |
1.0s |
| Memory Limit: |
256.0MB |
| Problem Description: |
The problem description places n adjacent rectangles on the horizontal axis, each rectangle having a width of 1, and the height of the rectangle I (1≤i≤n) is hi. These n rectangles form a histogram. For example, the height of the six rectangles is 3, 1, 6, 5, 2, 3, respectively.
Find the rectangle with the largest area in the given histogram, and its edges are parallel to the axis. For the example given above, the maximum rectangle as shown in the shaded portion, the area is 10. Input format the first line contains an integer n, which is the number of rectangles (1≤n≤1000). The second line contains n integers h1, h2, ..., HN, and the adjacent numbers are separated by a space. (1≤hi≤10000). Hi is the height of the first rectangle. The output format outputs a row that contains an integer that is the area of the largest rectangle within a given histogram. Sample Input 6 3 1 6 5 2 3 Sample output 10 |
//This problem has only 90 points
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cstdlib>5#include <algorithm>6 using namespacestd;7 Const intmaxn=1107;8 Long Longans,dp[maxn][11007],HIGH,N,NUM[MAXN];9 Ten voidSlove () One { AMemset (DP,0,sizeof(DP)); - for(intI=1; i<=n;i++) - { the for(intj=1; j<=high;j++) - { - if(NUM[I]>=J) dp[i][j]=dp[i-1][j]+1; -Ans=max (ans,dp[i][j]*j); + } - } + } A intMain () at { - //freopen ("In.txt", "R", stdin); -ans=0; high=0; -Cin>>N; - intleft=0, right=0, mid; - for(intI=1; i<=n;i++) in { -Cin>>Num[i]; toHigh=Max (high,num[i]); + } - slove (); thecout<<ans<<Endl; * return 0; $}
CCF the largest rectangle