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 N lines 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

题意:一条大街上有n个人点外卖,每个人每等一分钟就会增加一定的不满意度。给出每个人的坐标xi和每分钟增加的不满意度bi、

餐馆坐标x和外卖小哥走一公里需要的时间(1/v)。外卖小哥必须给每个人都送到,求顾客的不满意度和的最小值。

题解:由于不算外卖小哥等顾客拿外卖的时间(e_e),外卖小哥只要经过了顾客的位置,就直接把外卖给顾客。

可以把外卖小哥走过的位置简化为一个区间,要使区间内顾客不满意度和最短,外卖小哥最后送外卖的位置一定要在

区间端点。先按位置从左到右排序,设sum[i]为第一个到第n个人每分等一分钟增长的不满意度和,

dp[i][j][0]表示最后一次送外卖是在左端点,dp[i][j][1]表示在右端点。

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int INF=0x3f3f3f3f;
int a[];
int b[];
int dp[][][];
int sum[]; struct node
{
int x,b;
} s[]; bool cmp(node x,node y)
{
return x.x<y.x;
} int main()
{
int n,v,x;
while(~scanf("%d%d%d",&n,&v,&x))
{
sum[]=;
for(int i=; i<=n; i++)
scanf("%d%d",&s[i].x,&s[i].b);
memset(dp,INF,sizeof dp);
sort(s+,s+n+,cmp);
for(int i=;i<=n;i++)
sum[i]=sum[i-]+s[i].b;
for(int i=; i<=n; i++)
dp[i][i][]=dp[i][i][]=abs(s[i].x-x)*sum[n];
for(int l=; l<=n; l++)
for(int i=; i<=n-l+; i++)
{
int j=i+l-;
dp[i][j][]=min(dp[i][j][],dp[i+][j][]+abs(s[i+].x-s[i].x)*(sum[n]-sum[j]+sum[i]));
dp[i][j][]=min(dp[i][j][],dp[i+][j][]+abs(s[j].x-s[i].x)*(sum[n]-sum[j]+sum[i]));
dp[i][j][]=min(dp[i][j][],dp[i][j-][]+abs(s[j].x-s[i].x)*(sum[n]-sum[j-]+sum[i-]));
dp[i][j][]=min(dp[i][j][],dp[i][j-][]+abs(s[j].x-s[j-].x)*(sum[n]-sum[j-]+sum[i-]));
}
printf("%d\n",min(dp[][n][],dp[][n][])*v);
}
return ;
}

ZOJ - 3469 Food Delivery (区间dp)的更多相关文章

  1. ZOJ 3469 Food Delivery 区间DP

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

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

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

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

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

  4. ZOJ 3469 Food Delivery(区间DP)

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

  5. ZOJ 3469Food Delivery(区间DP)

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

  6. ZOJ3469 Food Delivery —— 区间DP

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

  7. [ZOJ]3541 Last Puzzle (区间DP)

    ZOJ 3541 题目大意:有n个按钮,第i个按钮在按下ti 时间后回自动弹起,每个开关的位置是di,问什么策略按开关可以使所有的开关同时处于按下状态 Description There is one ...

  8. ZOJ3469 Food Delivery 区间DP

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

  9. ZOJ 3469 Food Delivery (区间DP,经典)

    题意: 在x轴上有一家外卖餐馆,有n个顾客站在x轴上不同坐标上且叫了外卖,每个人的脾气不同,每1分钟没有收到外卖就会增加Fi点愤怒值,而外卖小哥的车是有速度的v-1/分钟,问怎样的送餐次序会让所有顾客 ...

随机推荐

  1. .NET Framework 各个版本介绍

    .NET Framework 1.1 自1.0版本以来的改进:自带了对mobile asp .net控件的支持.这在1.0版本是以附加功能方式实现的,现在已经集成到框架的内部.安全方面的变更 - 使得 ...

  2. H5拖拽 构造拖拽及缩放 pdf展示

    前言: 协助项目需要实现一个签名的功能. 功能说明:1.有文本签名和头像签名.2.头像签名需要实现可拖拽功能.3.需要展示的是pdf的文件并需要获取签名位于pdf文件的相对位置. 功能一:实现拖拽 思 ...

  3. Linux 特殊用户权限 suid,sgid, sticky

    每个进程会维护有如下6个ID: 真实身份 : real UID, readl GID --> 登录 shell 使用的身份 有效身份 : effective UID, effective GID ...

  4. elasticSearch(5.3.0)的评分机制的研究

    1.  ElasticSearch的评分 在用ElasticSearch作为搜索引擎的时候,如果采用关键字进行查询,ElasticSearch会对每个符合查询条件的文档进行评分,在5.3.0的版本中, ...

  5. oracle表空间自增长

    方式一:通过修改oracle database control 修改 第一步,点击开始--所有程序--Oracle - OraDb11g_home1--Database Control 第二步,通过g ...

  6. Redis中的数据对象

    redis对象 redis中有五种常用对象 我们所说的对象的类型大多是值的类型,键的类型大多是字符串对象,值得类型大概有以下几种,但是无论哪种都是基于redisObject实现的 redisObjec ...

  7. promise(3) '静态'方法

    要是人没有梦想,跟咸鱼又有什么两样了?一直恐惧读源码,哪怕是一个简单的库也是读百来行遇到难点就放弃了.对于新的东西也仅仅是知道它拿来干什么,社区资源在哪里,要用时就突击文档资源使用即可.未有过深入之心 ...

  8. Java软件系统功能设计实战训练视频教程

    Java软件系统功能设计实战训练视频教程 第01节课:整体课程介绍和杂项介绍第02节课:软件功能设计常见理念和方法第03节课:关于软件设计的一些思考第04节课:第一周作业的业务和相应模式:综合应用简单 ...

  9. iOS10 相关的隐私设置,

    最近下载了几个demo,总是一运行就崩,看了下崩溃日志,有几个是因为没在plist里设置因此权限,而现在iOS 10 开始对隐私权限更加严格, 如需使用隐私权限需要在工程的info.plist文件中声 ...

  10. 使用react-router setRouteLeaveHook的钩子函数

    今天在使用react-router setRouteLeaveHook的钩子函数,不知道怎么实验就是成功.最后功夫不负有心人,终于让我找到使用setRouteLeaveHook的方法了 1.我在网络上 ...