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. 502 IPO 上市

    详见:https://leetcode.com/problems/ipo/description/ C++: class Solution { public: int findMaximizedCap ...

  2. Hadoop工作流概念学习系列总述(一)

    不多说,这里,直接上干货!从这篇博客起,逐步分享如下: 1.工作流 2.Hadoop工作流(内置) 3.第三方框架--Azkaban(推荐外安装)

  3. 02.第二章_C++ Primer学习笔记_变量和基本类型

    2.1  基本内置类型 2.1.1  算术类型 算术类型包括两类:整型和浮点型 2.2  变量 2.3  复合类型 2.4  const限定符 2.5  处理类型 2.6  自定义数据结构

  4. 分层开发之C#分层

    假如没有用分层开发,仔细分析三人的开发过程,很容易发现其中的问题: >三人排队式的轮番工作,花费的时间是三人工作时间之和. >后面开发的人基本都是要先花费时间熟悉前面人的代码,否则开发难以 ...

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

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

  6. [BZOJ1040][ZJOI2008]骑士 基环树DP

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1040 题目给出了$n$个点和$n$条无向边,即一棵基环树或者基环树森林. 如果题目给的关系 ...

  7. Koa--基于Node.js平台的下一代web开发框架的安装

    koa 是由 Express 原班人马打造的,致力于成为一个更小.更富有表现力.更健壮的 Web 框架. 使用 koa 编写 web 应用,通过组合不同的 generator,可以免除重复繁琐的回调函 ...

  8. 801硬件检测工具DragonHD的使用

    801硬件检测工具DragonHD的使用 2018/11/28 13:39 版本:V1.0 开发板:SC3817R 1.客户要认证器件,使用了全志官方的工具:DragonHD.exe 打开之后可以见用 ...

  9. http响应头状态描述

    状态代码有三位数字组成,第一个数字定义了响应的类别,且有五种可能取值:1xx:指示信息--表示请求已接收,继续处理2xx:成功--表示请求已被成功接收.理解.接受3xx:重定向--要完成请求必须进行更 ...

  10. Android Studio -自定义LogCat的颜色

    博文地址 http://www.cnblogs.com/Loonger/p/6285344.html 先看看效果 (设置中的显示,下图) 步骤如下 File->Settings 或Ctrl + ...