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. jmeter(十九)调试工具Debug Sampler

    一.Debug Sampler介绍: 使用Jmeter开发脚本时,难免需要调试,这时可以使用Jmeter的Debug Sampler,它有三个选项:JMeter properties,JMeter v ...

  2. 微服务dubbo面试题

    dubbo的工作原理? dubbo支持的序列化协议? dubbo的负载均衡和高可用策略?动态代理策略? dubbo的SPI思想? 如何基于dubbo进行服务治理.服务降级.失败重试以及超时重试? du ...

  3. gbk编码文件传输json实例

    cline.php <?php $str='此地无银三百两'; $str = iconv('gbk', 'utf-8', $str); //Json只支持utf-8编码,如果不进行转码的话,服务 ...

  4. Spring-aop(一)

    写一个计算类,计算前后需要打印日志. interface ArithmeticCalculator { public int add(int i, int j); public int sub(int ...

  5. JavaScript也谈内存优化

    相对C/C++ 而言,我们所用的JavaScript 在内存这一方面的处理已经让我们在开发中更注重业务逻辑的编写.但是随着业务的不断复杂化,单页面应用.移动HTML5 应用和Node.js 程序等等的 ...

  6. 求N个数的最大公约数

    使用 “辗转相除法” 计算2个数的最大公因数: int GCD_2(int nNum1, int nNum2) { if (nNum1 > nNum2) { nNum1 = nNum1 ^ nN ...

  7. centos开机直接进入命令行

    找到文件,/etc/inittab 文件,在下面有一行 id:5:initdefault: 将上面的5改成3就可以了 5是图形界面 3是命令行界面 就是文本界面.

  8. 简洁的KVO -- 使用Block响应事件

    涉及内容: KVO,Runtime,Category,Block 首先创建NSObject的Category 举个例子是这样的: 随后定义你需要响应的Block结构 我简单一点就这样咯 typedef ...

  9. 看Spring Data如何简化数据操作

    Spring Data 概述 Spring Data 用于简化数据库访问,支持NoSQL 和 关系数据存储,其主要目标是使数据库的访问变得方便快捷. SpringData 项目所支持 NoSQL 存储 ...

  10. yii 和 zend studio 集成

    yii是基于测试驱动的,而zend studio是一个好用的ide.集成就是必须的. 本文适合喜欢使用ide的开发者,vim用户或者文本编辑器使用者请忽略. 本文使用的是最新的zend studio ...