题目:http://acm.hdu.edu.cn/showproblem.php?pid=1506
这个题目我最开始的思路是DP前i块时候的最大面积。后来发现不行。然后在DP前i快面积是,觉得左边和右边满足条件的是可以DP出来的。有了思路。
#include<bits/stdc++.h>
#define INF 1e18
#define inf 1e9
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define IOS ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std ;
typedef long long ll;
typedef unsigned long long ull;
const int _max = 100050;
ll a[_max],dpl[_max],dpr[_max];
int main(){
int n;
while(cin>>n){
if(!n) break;
for(int i = 1 ; i <= n ; i++) cin>>a[i];
memset(dpl,0,sizeof(dpl));
memset(dpr,0,sizeof(dpr));
for(int i = 2 ; i <= n ; i++){
if(a[i] <= a[i-1]){
int t = dpl[i-1]+1;
while(i-t-1>=1&&a[i-t-1]>=a[i]) t+=(dpl[i-t-1]+1);
dpl[i] = t;
}
}
for(int i = n-1 ; i >= 1 ; i--){
if(a[i] <= a[i+1]){
int t = dpr[i+1]+1;
while(i+t+1<=n&&a[i+t+1]>=a[i]) t+=(dpr[i+t+1]+1);
dpr[i] = t;
}
}
ll ans = 0;
for(int i = 1 ; i <= n ; i++){
ll cnt = a[i]*(dpl[i]+dpr[i]+1);
ans = max(ans,cnt);
// cout<<dpl[i]<<' '<<dpr[i]<<' '<<cnt<<endl;
}
cout<<ans<<endl;
}
return 0;
}