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. $(inherited) "$(SRCROOT) 修改.a文件的路径 --Library Search Paths

    $(inherited) "$(SRCROOT)/.a文件所在的文件名" //如果有多个.a文件格式就像这样 $(inherited) "$(SRCROOT)/xxxx& ...

  2. win7画板橡皮擦改变大小

    按住CTRL键不放,再按小键盘上的“+”号键,可以将橡皮擦放大

  3. Xn数列(codevs 1281)

    题目描述 Description 给你6个数,m, a, c, x0, n, g Xn+1 = ( aXn + c ) mod m,求Xn m, a, c, x0, n, g<=10^18 输入 ...

  4. logstash json和rubydebug 第次重启logstash都会把所有的日志读完 而不是只读入新输入的内容

    查看一下agent端的shipper的配置: # cat logstash_test2.shipper.conf input { file { path => ["/apps/logs ...

  5. jquery学习笔记---this关键字

    1.    在JavaScript的变量作用域里有一条规则“全局变量都是window对象的属性”.当执行 checkThis() 时相当于 window.checkThis(),因此,此时checkT ...

  6. 一般处理程序获取session值

    1.要在一般处理程序中获取其他页面的session值,需要引用名空间: using System.Web.SessionState; 2.然后继承一个接口:IRequiresSessionState, ...

  7. 与你相遇好幸运,mbview的mbtiles文件分析

    mbview是一个查看.mbtiles文件的本地程序. https://github.com/mapbox/mbview .mbtiles文件就是一个Sqlite文件,用Navicat Premium ...

  8. jQuery Moblie 学习之page、button、theme、panel、listview、controlgroup、navbar等(一)

    1.jQTouch jQTouch与jQuery Moblie十分相似,也是一个jQuery插件,同样也支持HTML页面标签驱动,实现移动设备视图切换效果.不同的是它是专为WebKit内核的浏览器打造 ...

  9. Android 中this、getContext()、getApplicationContext()、getApplication()、getBaseContext() 之间的区别

    : 知之为知之,不知为不知是知也! 使用this, 说明当前类是context的子类,一般是activity application等; this:代表当前,在Activity当中就是代表当前的Act ...

  10. 【PHP数组的使用】

    PHP数组使用关键字array标识,数组内的元素可以是任意类型,而且可以不是同一种类型,这和c.java不同. 遍历数组的方法可以使用foreach,也可以使用for循环 可以使用print_r或者v ...