I'm going to give you a sequence and take a number from the inside. The value that can be removed from the team head or the end of the team multiplied by the order I (and a few taken out) to accumulate and the maximum value;
DP "I" "j" means to go to I times from the left to the maximum value of J, and then push it down;
dp "I" "J" =max (dp "I-1" "J" *num "J" *i,num "I-1" "J" +num "n-i+j+1" *i) Note that the case of J is 0; it's a hole. Num Array is opened as a local variable WA open for the int64 or WA really no words /c2>
#include<stdio.h>#include<iostream>#include<string.h>using namespaceStd;intDp[ .][ .],Num[ .];int Max(intA,intB){returnA>B?A:B;}int Main(){intN,I,J; while(~scanf("%d",&N)){ for(I=1;I<=N;I++)scanf("%d",&Num[I]);memset(Dp,0,sizeof(Dp)); for(I=1;I<=N;I++){ for(J=0;J<=I;J++){if(J>0)Dp[I][J]=Max(Dp[I-1][J-1]+Num[J]*I,Dp[I-1][J]+Num[N-I+J+1]*I);ElseDp[I][J]=Dp[I-1][J]+Num[N-I+J+1]*I;}}intMax=0; for(I=0;I<=N;I++){Max=Max(Max,Dp[N][I]);//printf ("%i64d\n", Dp[n][i]);}printf("%d\ n",Max);}return 0;}
POJ 3186 interval DP