When we are focusing on solving problems, we usually prefer to stay in front of computers rather than go out for lunch. At this time, we may call for food delivery.

Suppose there are N people living in a straight street that is just lies on an X-coordinate axis. The ith person's coordinate is Xi meters. And in the street there is a take-out restaurant which has coordinates X meters. One day at lunchtime, each person takes an order from the restaurant at the same time. As a worker in the restaurant, you need to start from the restaurant, send food to the N people, and then come back to the restaurant. Your speed is V-1 meters per minute.

You know that the N people have different personal characters; therefore they have different feeling on the time their food arrives. Their feelings are measured by Displeasure Index. At the beginning, the Displeasure Index for each person is 0. When waiting for the food, the ith person will gain Bi Displeasure Index per minute.

If one's Displeasure Index goes too high, he will not buy your food any more. So you need to keep the sum of all people's Displeasure Index as low as possible in order to maximize your income. Your task is to find the minimal sum of Displeasure Index.

Input

The input contains multiple test cases, separated with a blank line. Each case is started with three integers N ( 1 <= N <= 1000 ), V ( V > 0), X ( X >= 0 ), then Nlines followed. Each line contains two integers Xi ( Xi >= 0 ), Bi ( Bi >= 0), which are described above.

You can safely assume that all numbers in the input and output will be less than 231- 1.

Please process to the end-of-file.

Output

For each test case please output a single number, which is the minimal sum of Displeasure Index. One test case per line.

Sample Input

5 1 0
1 1
2 2
3 3
4 4
5 5

Sample Output

55

题目大意:

在一个一维坐标轴上,有若干个点,已知餐厅的位置,以及外卖员的速度,不满意度为Bi*等待的时间,求外卖员从餐厅送到各个点的最小总不满意度。

可以将餐厅加进去并排列,以餐厅为中心,向外扩:

dp[i][j][0]:(需要将除了区间以内的数全部乘上这个差值)

dp[i+1][j][0]+(pre[i]+pre[n]-pre[j])*(a[i+1].x-a[i].x) 、dp[i+1][j][1]+(pre[i]+pre[n]-pre[j])*(a[j].x-a[i].x)

dp[i][j][1]:

dp[i][j-1][0]+(pre[i-1]+pre[n]-pre[j-1])*(a[j].x-a[i].x)、dp[i][j-1][1]+(pre[i-1]+pre[n]-pre[j-1])*(a[j].x-a[j-1].x)

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int INF=0x3f3f3f3f;
long long dp[][][],pre[];
int n,v,x;
struct p
{
int x,b;
}a[];
bool cmp(p a,p b)
{
return a.x<b.x;
}
int main()
{
ios::sync_with_stdio(false);
while(cin>>n>>v>>x)
{
memset(dp,INF,sizeof dp);
for(int i=;i<n;i++)
cin>>a[i].x>>a[i].b;
a[n].x=x,a[n].b=;///将餐厅点加进去
sort(a,a+n+,cmp);
int pos=;///找到餐厅的位置
for(int i=;i<=n;i++)
if(a[i].x==x&&a[i].b==)
pos=i;
dp[pos][pos][]=dp[pos][pos][]=;
pre[]=a[].b;
for(int i=;i<=n;i++)///处理前缀和
pre[i]=pre[i-]+a[i].b;
for(int i=pos;i>=;i--)
for(int j=pos;j<=n;j++)
{
if(i==j) continue;
dp[i][j][]=min(dp[i][j][],dp[i+][j][]+(pre[i]+pre[n]-pre[j])*(a[i+].x-a[i].x));///左,前左
dp[i][j][]=min(dp[i][j][],dp[i+][j][]+(pre[i]+pre[n]-pre[j])*(a[j].x-a[i].x));///左,前右
dp[i][j][]=min(dp[i][j][],dp[i][j-][]+(pre[i-]+pre[n]-pre[j-])*(a[j].x-a[i].x));///右,前左
dp[i][j][]=min(dp[i][j][],dp[i][j-][]+(pre[i-]+pre[n]-pre[j-])*(a[j].x-a[j-].x));///右,前右
}
cout<<v*min(dp[][n][],dp[][n][])<<'\n';///v代表的是每米花多少时间
}
return ;
}

Food Delivery (区间DP)的更多相关文章

  1. ZOJ 3469Food Delivery(区间DP)

    Food Delivery Time Limit: 2 Seconds      Memory Limit: 65536 KB When we are focusing on solving prob ...

  2. ZOJ3469 Food Delivery —— 区间DP

    题目链接:https://vjudge.net/problem/ZOJ-3469 Food Delivery Time Limit: 2 Seconds      Memory Limit: 6553 ...

  3. ZOJ 3469 Food Delivery 区间DP

    这道题我不会,看了网上的题解才会的,涨了姿势,现阶段还是感觉区间DP比较难,主要是太弱...QAQ 思路中其实有贪心的意思,n个住户加一个商店,分布在一维直线上,应该是从商店开始,先向两边距离近的送, ...

  4. ZOJ3469 Food Delivery 区间DP

    题意:有一家快餐店送外卖,现在同时有n个家庭打进电话订购,送货员得以V-1的速度一家一家的运送,但是每一个家庭都有一个不开心的值,每分钟都会增加一倍,值达到一定程度,该家庭将不会再订购外卖了,现在为了 ...

  5. ZOJ - 3469 Food Delivery (区间dp)

    When we are focusing on solving problems, we usually prefer to stay in front of computers rather tha ...

  6. zoj 3469 Food Delivery 区间dp + 提前计算费用

    Time Limit: 2 Seconds      Memory Limit: 65536 KB When we are focusing on solving problems, we usual ...

  7. ZOJ 3469 Food Delivery(区间DP好题)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4255 题目大意:在x轴上有n个客人,每个客人每分钟增加的愤怒值不同. ...

  8. 区间DP小结

    也写了好几天的区间DP了,这里稍微总结一下(感觉还是不怎么会啊!). 但是多多少少也有了点感悟: 一.在有了一点思路之后,一定要先确定好dp数组的含义,不要模糊不清地就去写状态转移方程. 二.还么想好 ...

  9. ZOJ 3469 Food Delivery(区间DP)

    https://vjudge.net/problem/ZOJ-3469 题意:在一条直线上有一个餐厅和n个订餐的人,每个人都有随时间上升的不满意值,从餐厅出发,计算出送完时最小的不满意值总和. 思路: ...

  10. [kuangbin带你飞]专题二十二 区间DP

            ID Origin Title   17 / 60 Problem A ZOJ 3537 Cake   54 / 105 Problem B LightOJ 1422 Hallowee ...

随机推荐

  1. Android APK加壳技术方案

    Android APK加壳技术方案[1] Android APK加壳技术方案[2]

  2. drbd 配置

    DRBD(Distributed Replicated Block Device),DRBD 号称是 "网络 RAID",开源软件,由 LINBIT 公司开发.DRBD实际上是一种 ...

  3. js 判断客户端系统

    function detectOS() { var sUserAgent = navigator.userAgent; var isWin = (navigator.platform == " ...

  4. 使用JS移除select的某些选项

    var arrvalue = new Array("1", "3", "4", "5", "6", ...

  5. log4go折腾

    导包 go get -u github.com/alecthomas/log4go log4go.xml配置 <logging> <filter enabled="true ...

  6. 动态栅格(DEM)图层实现服务端渲染

    PS:此处动态图层指,图层文件都放在经过注册的文件目录里,可以通过文件名动态加载图层 动态加载的矢量图层,可以实现客户端和服务端的定制渲染,但栅格一般是不能再渲染的,以下介绍可行的方法 建立一个很简单 ...

  7. webapi参数处理get过个参数

    // GET api/values/5 [HttpGet("{logInName}/{pwd}/{orgId}")] public LogInOutPut Get(string l ...

  8. iOS逆向实战与工具使用(微信添加好友自动确认)

    iOS逆向实战与工具使用(微信添加好友自动确认) 原文链接 源码地址 WeChatPlugin-iOS Mac OS 版微信小助手(远程控制.消息防撤回.自动回复.微信多开) 一.前言 本篇主要实现在 ...

  9. 微软将于12月起开始推送Windows 10 Mobile

    [环球科技报道 记者 陈薇]据瘾科技网站10月8日消息,根据微软Lumia官方Faceboo发布的消息,新版系统Windows 10 Mobile 将会12月起陆续开始推送. 推送的具体时程根据地区. ...

  10. 【洛谷2019 OI春令营】期中考试

    T68402 扫雷 题目链接:传送门 题目描述 扫雷,是一款单人的计算机游戏.游戏目标是找出所有没有地雷的方格,完成游戏:要是按了有地雷的方格,游戏失败.现在 Bob 正在玩扫雷游戏,你作为裁判要判断 ...