Advertisement
LZsolar

CUBE-025: A-Point

Mar 30th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long int lld;
  4. lld qs[601],dp[601][601];
  5.  
  6. lld cut(int f,int l){
  7.     if(f==l){return 0;}
  8.     if(dp[f][l]!=0){return dp[f][l];}
  9.    
  10.     lld sum=0;
  11.     for(int i=f;i<l;i++){
  12.         lld a= qs[l]-qs[i],b=qs[i]-qs[f-1];
  13.         if(a>b){sum=max(sum,(b*2)+a+cut(f,i)+cut(i+1,l));}
  14.         else   {sum=max(sum,b+(a*2)+cut(f,i)+cut(i+1,l));}
  15.     }
  16.     return dp[f][l]=sum;
  17. }
  18.  
  19. int main(){
  20.     int n;
  21.     scanf("%d",&n);
  22.    
  23.     for(int i=1;i<=n;i++){
  24.         scanf("%lld",&qs[i]);
  25.         qs[i]=qs[i]+qs[i-1];
  26.     }
  27.     lld ans=cut(1,n);
  28.    
  29.     printf("%lld",ans);
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement