Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
在论坛上学的DP,却总是TLE,恳请高人指点!!这是我的代码 #include<stdio.h> int left[100005],right[100005],i,j,k,n; __int64 brick[100005]={0},max,l; int main(int argc, char* argv[]) { while(scanf("%d",&n)>0) { if(n==0) break; for(i=1;i<=n;i++) { scanf("%I64d",&brick[i]); left[i]=right[i]=i; } brick[i+1]=brick[0]=0; for(i=1;i<=n;i++) { while(brick[left[i]-1]>=brick[i]) {left[i]=left[left[i]-1];} } for(i=n;i>=1;i--) { while(brick[right[i]+1]>=brick[i]) {right[i]=right[right[i]+1];} } max=0; for(i=1;i<=n;i++) { l=right[i]-left[i]+1; if(l*brick[i]>max) { max=l*brick[i]; } } printf("%I64d\n",max); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator