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 |
太高兴啦,小菜分享代码#include<stdio.h> int mmg[2000][2000]; int mg[2000]; int main() { int n,i,j,sum,t,max; while(scanf("%d",&n)!=EOF){ for(i=0;i<n;i++) scanf("%d",&mg[i]); if(n==1){printf("%d\n",mg[0]);continue;} sum=0;mmg[0][n-1]=0;t=1; for(i=n-2;i>=0;i--){ sum+=mg[i+1]*t; t++; mmg[0][i]=sum; } mmg[0][0]+=mg[0]*n; max=mmg[0][0]; sum=0;t=1; for(i=1;i<n;i++){ sum+=mg[i-1]*t; t++; mmg[i][n-1]=sum; } mmg[n-1][n-1]+=mg[n-1]*n; if(max<mmg[n-1][n-1]) max=mmg[n-1][n-1]; for(i=1;i<n-1;i++) for(j=n-2;j>=i;j--){ t=i+n-j-1; mmg[i][j]=(mmg[i-1][j]+mg[i-1]*t)>(mmg[i][j+1]+mg[j+1]*t)?(mmg[i-1][j]+mg[i-1]*t):(mmg[i][j+1]+mg[j+1]*t); if(i==j){ mmg[i][j]+=mg[i]*n; if(max<mmg[i][j]) max=mmg[i][j]; } } printf("%d\n",max); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator