# ZOJ 3469(区间DP)

//第一次做区间DP的题 看了别人的题解写的
//解法只要将各个点（包括餐厅的位置）按照距离原点的距离升序排序
//然后从餐厅这个点开始向两侧区间DP
// dp[i][j][0] 表示 当前点送完了区间[i,j]的外卖并且在区间的左端点I点
// dp[i][j][1] 表示 当前点送完了区间[i,j]的外卖并且在区间的右端点J点
//那么dp[i][j][0] 可由dp[i+1][j][0] 和 dp[i+1][j][1] 推出
//        dp[i][j][1] 可由dp[i][j-1][0] 和  dp[i][j-1][1]  推出
#include <iostream>
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "algorithm"
#include <queue>
#include <stack>
#define N 100005

#define INF 1<<30
using namespace std;
int dp[1005][1005][2];
int sum[1005];

struct node {
int x, v;
}point[1005];

int cmp(node a, node b)
{
return a.x < b.x;
}

int cal(int a, int b)
{
return sum[b]-sum[a - 1];
}
int main()
{
int n, v, x, op;
//freopen("t", "r", stdin);
while(scanf("%d%d%d", &n, &v, &x) != EOF)
{
for(int i = 1; i <= n; i++)
scanf("%d%d", &point[i].x, &point[i].v);
point[++n].x = x, point[n].v = 0;
sort(point+1, point+n+1, cmp);
sum[0] = 0;
for(int i = 1; i <= n; i++)
{
if(point[i].x == x )
{
op = i;
}
sum[i] = sum[i-1] + point[i].v;
}

for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
dp[i][j][0] = dp[i][j][1] = INF;

dp[op][op][0] = dp[op][op][1] = 0;

for( int i = op; i >= 1; i--)
for( int j = op; j <= n; j++)
{
int cost = cal(1, i - 1) + cal(j + 1, n);
if(i == j) continue;
dp[i][j][0] = min( dp[i][j][0] , dp[i + 1][j][0] + (point[i+1].x - point[i].x) * ( cost + point[i].v) );
dp[i][j][0] = min( dp[i][j][0] , dp[i + 1][j][1] + (point[j].x - point[i].x) * ( cost +point[i].v ) );
dp[i][j][1] = min( dp[i][j][1] , dp[i][j - 1][0] + (point[j].x - point[i].x)  * (cost + point[j].v ) );
dp[i][j][1] = min( dp[i][j][1] , dp[i][j - 1][1] + (point[j].x - point[j-1].x) * (cost + point[j].v ) );
}

printf("%d\n", v*(min( dp[1][n][0], dp[1][n][1])));
}
}



#### zoj 3469 Food Delivery(区间DP，好题，)

2014-02-11 10:56:34

#### ZOJ3469:Food Delivery(区间DP)

2014-08-11 14:41:20

#### zoj 3469 Food Delivery 区间DP

2016-04-18 20:54:16

#### zoj3469(区间dp)

2016-06-07 18:43:40

#### ZOJ 3537 Cake(凸包判定+区间DP)

2016-03-23 08:25:08

#### zoj 3537 Cake 【凸包 + 区间dp】 【最优三角剖分】

2015-12-23 12:58:52

#### zoj 3160(区间dp 简单)

2014-02-18 19:07:35

#### ZOJ 3469 区间dp

2014-03-12 00:34:40

#### zoj 3469 区间dp

2014-05-23 21:35:22

#### ZOJ 3469 区间DP

2017-08-01 21:07:33