Time Limit: 2 Seconds      Memory Limit: 65536 KB


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 byDispleasure 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


Author: LI, Cheng
Contest: ZOJ Monthly, February 2011

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define X first
#define Y second
using namespace std; const int N = 1005;
const int INF = 0x3f3f3f3f;
typedef pair<int, int> pii; pii p[N];
int sum[N]; int dp[N][N][2];
int n, v, x; int get(int i, int j, int f)
{
if(i == j) return dp[i][j][f];
int& res = dp[i][j][f];
if(res != -1) return res;
res = INF;
if(!f) {
int add = sum[n] - (sum[j] - sum[i]);
res = min(res, get(i + 1, j, 0) + (p[i + 1].X - p[i].X) * add);
res = min(res, get(i + 1, j, 1) + (p[j].X - p[i].X) * add);
}
else {
int add = sum[n] - (sum[j - 1] - sum[i - 1]);
res = min(res, get(i, j - 1, 1) + (p[j].X - p[j - 1].X) * add);
res = min(res, get(i, j - 1, 0) + (p[j].X - p[i].X) * add);
}
return res;
} int main()
{
while(~scanf("%d%d%d", &n, &v, &x))
{
for(int i = 1; i <= n; ++i) scanf("%d%d", &p[i].X, &p[i].Y);
p[++n].X = x;
p[n].Y = 0;
sort(p + 1, p + n + 1);
sum[0] = 0;
for(int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + p[i].Y; int xpos;
memset(dp, -1, sizeof dp);
for(int i = 1; i <= n; ++i) if(p[i].X == x) { xpos = i; break; }
for(int i = 1; i <= n; ++i) dp[i][i][0] = dp[i][i][1] = INF;
dp[xpos][xpos][0] = dp[xpos][xpos][1] = 0; printf("%d\n", v * min(get(1, n, 0), get(1, n, 1)));
}
return 0;
}

  

zoj 3469 Food Delivery 区间dp + 提前计算费用的更多相关文章

  1. ZOJ 3469 Food Delivery 区间DP

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

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

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

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

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

  4. 洛谷P1220关路灯[区间DP 提前计算代价]

    题目描述 某一村庄在一条路线上安装了n盏路灯,每盏灯的功率有大有小(即同一段时间内消耗的电量有多有少).老张就住在这条路中间某一路灯旁,他有一项工作就是每天早上天亮时一盏一盏地关掉这些路灯. 为了给村 ...

  5. ZOJ 3469 Food Delivery(区间DP)

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

  6. ZOJ 3469Food Delivery(区间DP)

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

  7. ZOJ3469 Food Delivery —— 区间DP

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

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

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

  9. ZOJ3469 Food Delivery 区间DP

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

随机推荐

  1. July 4th, Week 28th Monday, 2016

    Goals determine what you are going to be. 你的目标决定你将成为怎样的人. What are your goals? What kind of people y ...

  2. mysql my.cnf配置文件详解

    本配置文件针对Dell R710,双至强E5620.16G内存的硬件配置.CentOS 5.6 64位系统,MySQL 5.5.x 稳定版.适用于日IP 50-100w,PV 100-300w的站点, ...

  3. oracle sqlplus存储过程控制台输出信息

    如果你是使用PL/sql工具,在command 窗口下执行set serveroutput on 然后exec sp;可以看到了或者在sqlplus 中执行上面的代码

  4. IOS管理文件和目录NSFileManager

    1.常见的NSFileManager文件方法 -(NSData *)contentsAtPath:path //从一个文件读取数据 -(BOOL)createFileAtPath: path cont ...

  5. Oracle Redo Log

    http://blog.itpub.net/27039319/viewspace-2120623/ 11.2和11.2以下的区别:http://blog.itpub.net/27039319/view ...

  6. C语言的OOP实践(OOC)

    OOC 面向对象 C 语言编程实践 - 文章 - 伯乐在线http://blog.jobbole.com/105105/ ---硬着头皮看完了,但是感觉还是抽象有不理解的地方,感觉用C实现OOP好难啊 ...

  7. [LeetCode] TwoSum

    Given an array of integers, find two numbers such that they add up to a specific target number. The ...

  8. tornado使用(Mac)

    安装需求 Tornado 在 Python 2.5, 2.6, 2.7 中都经过了测试.要使用 Tornado 的所有功能,你需要安装 PycURL (7.18.2 或更高版本) 以及 simplej ...

  9. 使用PHP获取时间今天 明天 昨天 时间戳的详解

    使用php获取时间今天明天昨天时间戳 2013-06-20 11:12 <?php echo "今天:".date("Y-m-d")."< ...

  10. C语言中结构体的位域(bit-fields)

    转自:http://blog.sina.com.cn/s/blog_6240b5980100tcba.html 有些信息在存储时,并不需要占用一个完整的字节, 而只需占几个或一个二进制位.例如在存放一 ...