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. 解决spring boot websocket

    在网上找的demo写了一个小例子,本地开发测试都很正常,但是部署在tomcat就各种坑 1.MyWebSocket不要用spring 注解标注 2.main方法对应的类继承SpringBootServ ...

  2. python工具之exccel模板生成报表

    from Db import Db from log import log import xlwt import xlrd from xlutils.copy import copy import s ...

  3. AJPFX关于对集合中的元素删除操作和注意点

    import java.util.ArrayList;import java.util.Iterator;import java.util.List; public class ForeTest2 { ...

  4. unity内存管理

    最近一直在研究unity的内存加载,因为它是游戏运行的重中之重,如果不深入理解和合理运用,很可能导致项目因内存太大而崩溃. 详细说一下细节概念:AssetBundle运行时加载:来自文件就用Creat ...

  5. react ant design路由配置

    最初的时候,只使用了antd中的menu,header和footer都是自己写的组件,在写路由时,总是报如下错误: 相关的路由配置如下: 在网上查的说是组件未暴露出去或者是return 这一行必须有个 ...

  6. ML-学习提纲1

    http://www.sohu.com/a/130379077_468714 本文用一系列「思维导图」由浅入深的总结了「统计学」领域的基础知识,是对之前系列文章做的一次完整的梳理,也是我至今为止所有与 ...

  7. centos7 搭建双网卡bond1(主备模式)实例

    前景须知: 在redhat6 中网卡叫bond,在redhat7及centos7中改名team,此处只记录centos7中双网卡主备搭建过程. 应用情景:实现网络的高可用,防止一条网线或交换机故障影响 ...

  8. CentOS 6.5下安装Python 3.5.2(与Python2并存)

    CentOS 6.5下安装Python 3.5.2(与Python2并存) 安装步骤 1,准备编译环境(环境不对,在安装过程中可能遇到各种问题.比如wget无法下载链接的文件) yum groupin ...

  9. android打包需要的图标

    ldpi:mdpi:hdpi:xhdpi:xxhdpi=3:4:6:8:12 大小: 32x32.png 48 72 96 144

  10. 枚举 || CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution

    给出N*M矩阵,对于该矩阵有两种操作: 1.交换两列,对于整个矩阵只能操作一次 2.每行交换两个数. 交换后是否可以使每行都递增. *解法:N与M均为20,直接枚举所有可能的交换结果,进行判断 每次枚 ...