https://codeforces.com/contest/1519/problem/D
思路:
刚好最近在整理区间dp。
这题 看着像个区间dp.
dp[l,r]为反转这段区间获得的新价值。
然后递归[l+1,r-1]
并且dp状态记录下来。
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=5e3+100;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar(); while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL a[maxn],b[maxn];
LL dp[maxn][maxn];
LL n;
LL dfs(LL l,LL r){
if(l>=r) return 0;
if(dp[l][r]!=-1) return dp[l][r];
dp[l][r]=dfs(l+1,r-1)+a[l]*b[r]+a[r]*b[l]-a[l]*b[l]-a[r]*b[r];
return dp[l][r];
}
int main(void){
cin.tie(0);std::ios::sync_with_stdio(false);
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++) cin>>b[i];
LL sum=0;
for(int i=1;i<=n;i++) sum+=a[i]*b[i];
memset(dp,-1,sizeof(dp));
LL res=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
res=max(res,dfs(i,j));
}
}
cout<<sum+res<<"\n";
return 0;
}