# BZOJ 2037 区间DP

f[i][j]表示从第i个到第j个之间的蛋都被收完了
f[i][j][0]表示在地点i f[i][j][1]表示在地点j

f[i][j][0]=max(f[i+1][j][0]-(node[i+1].x-node[i].x)*(sumv[n]-sumv[j]+sumv[i]),
f[i+1][j][1]-(node[j].x-node[i].x)*(sumv[n]-sumv[j]+sumv[i])),
f[i][j][1]=max(f[i][j-1][0]-(node[j].x-node[i].x)*(sumv[n]-sumv[j-1]+sumv[i-1]),
f[i][j-1][1]-(node[j].x-node[j-1].x)*(sumv[n]-sumv[j-1]+sumv[i-1]));

//By SiriusRen
#include <cstdio>
#include <algorithm>
using namespace std;
int n,x0,sumy,sumv[1005],f[1005][1005][2];
struct Node{int x,y,v;}node[1005];
bool cmp(Node a,Node b){return a.x<b.x;}
int main(){
scanf("%d%d",&n,&x0);
for(int i=1;i<=n;i++)scanf("%d",&node[i].x);
for(int i=1;i<=n;i++)scanf("%d",&node[i].y),sumy+=node[i].y;
for(int i=1;i<=n;i++)scanf("%d",&node[i].v);
node[++n].x=x0;
sort(node+1,node+1+n,cmp);
for(int i=1;i<=n;i++){
if(node[i].x!=x0)f[i][i][0]=f[i][i][1]=0xcfffffff;
sumv[i]=sumv[i-1]+node[i].v;
}
for(int i=n;i;i--)
for(int j=i+1;j<=n;j++)
f[i][j][0]=max(f[i+1][j][0]-(node[i+1].x-node[i].x)*(sumv[n]-sumv[j]+sumv[i]),
f[i+1][j][1]-(node[j].x-node[i].x)*(sumv[n]-sumv[j]+sumv[i])),
f[i][j][1]=max(f[i][j-1][0]-(node[j].x-node[i].x)*(sumv[n]-sumv[j-1]+sumv[i-1]),
f[i][j-1][1]-(node[j].x-node[j-1].x)*(sumv[n]-sumv[j-1]+sumv[i-1]));
printf("%.3lf\n",0.001*(max(f[1][n][0],f[1][n][1])+sumy));
}

posted @ 2016-10-30 00:01  SiriusRen  阅读(135)  评论(0编辑  收藏  举报