POJ 3186 interval DP

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.