zoj 3469 Food Delivery 区间dp + 提前计算费用
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 + 提前计算费用的更多相关文章
- ZOJ 3469 Food Delivery 区间DP
这道题我不会,看了网上的题解才会的,涨了姿势,现阶段还是感觉区间DP比较难,主要是太弱...QAQ 思路中其实有贪心的意思,n个住户加一个商店,分布在一维直线上,应该是从商店开始,先向两边距离近的送, ...
- ZOJ - 3469 Food Delivery (区间dp)
When we are focusing on solving problems, we usually prefer to stay in front of computers rather tha ...
- ZOJ 3469 Food Delivery(区间DP好题)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4255 题目大意:在x轴上有n个客人,每个客人每分钟增加的愤怒值不同. ...
- 洛谷P1220关路灯[区间DP 提前计算代价]
题目描述 某一村庄在一条路线上安装了n盏路灯,每盏灯的功率有大有小(即同一段时间内消耗的电量有多有少).老张就住在这条路中间某一路灯旁,他有一项工作就是每天早上天亮时一盏一盏地关掉这些路灯. 为了给村 ...
- ZOJ 3469 Food Delivery(区间DP)
https://vjudge.net/problem/ZOJ-3469 题意:在一条直线上有一个餐厅和n个订餐的人,每个人都有随时间上升的不满意值,从餐厅出发,计算出送完时最小的不满意值总和. 思路: ...
- ZOJ 3469Food Delivery(区间DP)
Food Delivery Time Limit: 2 Seconds Memory Limit: 65536 KB When we are focusing on solving prob ...
- ZOJ3469 Food Delivery —— 区间DP
题目链接:https://vjudge.net/problem/ZOJ-3469 Food Delivery Time Limit: 2 Seconds Memory Limit: 6553 ...
- [ZOJ]3541 Last Puzzle (区间DP)
ZOJ 3541 题目大意:有n个按钮,第i个按钮在按下ti 时间后回自动弹起,每个开关的位置是di,问什么策略按开关可以使所有的开关同时处于按下状态 Description There is one ...
- ZOJ3469 Food Delivery 区间DP
题意:有一家快餐店送外卖,现在同时有n个家庭打进电话订购,送货员得以V-1的速度一家一家的运送,但是每一个家庭都有一个不开心的值,每分钟都会增加一倍,值达到一定程度,该家庭将不会再订购外卖了,现在为了 ...
随机推荐
- 【leetcode】Integer to Roman & Roman to Integer(easy)
Roman to Integer Given a roman numeral, convert it to an integer. Input is guaranteed to be within t ...
- 【XLL API 函数】xlSheetId
查找命名的工作表ID,用于外部引用. 原型 Excel12(xlSheetId, LPXLOPER12 pxRes, 1, LPXLOPER12 pxSheetName); 参数 pxSheetNam ...
- September 8th 2016 Week 37th Thursday
The secret of high-impact business is early preparation. 高效商务,赢在未雨绸缪. Early and best preparation is ...
- CityEngine基于规则贴图的实现技巧
转自:http://blog.sina.com.cn/s/blog_841eeb5201010p3e.html CityEngine在贴图的实现过程有两种方式:第一种是通过i(geometryPath ...
- python如何一行输入多个值
python2的raw_input以及python3的input获取的是整行的字符串.读进来后,字符串有着著名的split可以根据分隔符拆解成子串组成的list. 对于list内的对象,需要的采取转换 ...
- 直接放个DB2 SQL STATEMENT大全好了!
SQL statements This topic contains tables that list the SQL statements classified by type. SQL sch ...
- NYOJ之猴子吃桃问题
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAskAAAIMCAIAAACIcqa9AAAgAElEQVR4nO3dO3Li3BaG4TMJcgbi1A
- 3.2 STL中的函数对象类模板
*: STL中有一些函数对象类模板,如下所示: 1)例如要求两个double类型的x 和y 的积,可以: multiplies<double>()(x,y); 该表达式的值就是x*y的值. ...
- MVC – 4.mvc初体验(2)
5.显示学员列表 效果 数据表 5.1 首先,在文件夹Models新建一个新建项(W),选择ADO.NET 实体数据模型 (SingleTest.edmx) 5.2 建一个控制器,StudentsCo ...
- Application.ProcessMessages用法
参考:http://cqujsjcyj.iteye.com/blog/380926 我想你可能还有点模糊.举个例子容易明白:假如你的窗体上有两个按钮,一个“计算”,一个“停止”, 如果你的计算是密集运 ...