CF-1155 D.Beautiful Array

Subject to the effect: There are a number of columns, and a digital x, you can be this period the number of columns in continuous sequence while this figure is multiplied by x (of course, can not multiply), and then ask you how much is the largest sub-segment and

Practice: dp, you know

#include<iostream>
#include<cstdio>
using namespace std;
long long dp[3],x,ans;
int n;
int main(){
    scanf("%d",&n);
    cin>>x;
    long long a;
    for(int i=1;i<=n;i++){
        cin>>a;
        dp[0]=max(0LL,dp[0]+a);
        dp[1]=max(dp[0],dp[1]+x*a);
        dp[2]=max(dp[1],dp[2]+a);
        ans=max(ans,dp[2]);
    }
    cout<<ans<<endl;
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/thmyl/p/11704151.html