ACM PKU 2559 Largest Rectangle in a Histogram http://acm.pku.edu.cn/JudgeOnline/problem?id=2559
生活随笔
收集整理的這篇文章主要介紹了
ACM PKU 2559 Largest Rectangle in a Histogram http://acm.pku.edu.cn/JudgeOnline/problem?id=2559
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
關于覆蓋,用DP是一種很不錯的解決方法,時效也很不錯....
這題目把圖一畫就很明確了,沒有說明的必要了。
#include <iostream> using namespace std; __int64 height[100001]; int main () { int n; int left[100001]; int right[100001]; __int64 max=0,temp=0; while (scanf("%d",&n) && n) {int i=0;memset(height,0,sizeof(height));right[0]=0;left[n-1]=n-1;for(; i<n;i++){scanf("%I64d",&height[i]); }for(i=1;i<n;i++){right[i]=i;while(right[i]>0&&height[i]<=height[right[i]-1])right[i]=right[right[i]-1];}max=height[n-1];for(i=n-2;i>=0;i--){left[i]=i;while(left[i]<n-1&&height[left[i]+1]>=height[i])left[i]=left[left[i]+1];temp=(left[i]-right[i]+1)*height[i];if(temp>max)max=temp;}printf("%I64d\n",max);} return 0; }轉載于:https://www.cnblogs.com/Chinese-Coder-Clarence/articles/2039235.html
總結
以上是生活随笔為你收集整理的ACM PKU 2559 Largest Rectangle in a Histogram http://acm.pku.edu.cn/JudgeOnline/problem?id=2559的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Mac下Alt键配置
- 下一篇: android代码设置drawable,