ZOJ - 3469 Food Delivery (区间dp)
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)的更多相关文章
- ZOJ 3469 Food Delivery 区间DP
这道题我不会,看了网上的题解才会的,涨了姿势,现阶段还是感觉区间DP比较难,主要是太弱...QAQ 思路中其实有贪心的意思,n个住户加一个商店,分布在一维直线上,应该是从商店开始,先向两边距离近的送, ...
- zoj 3469 Food Delivery 区间dp + 提前计算费用
Time Limit: 2 Seconds Memory Limit: 65536 KB When we are focusing on solving problems, we usual ...
- ZOJ 3469 Food Delivery(区间DP好题)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4255 题目大意:在x轴上有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的速度一家一家的运送,但是每一个家庭都有一个不开心的值,每分钟都会增加一倍,值达到一定程度,该家庭将不会再订购外卖了,现在为了 ...
- ZOJ 3469 Food Delivery (区间DP,经典)
题意: 在x轴上有一家外卖餐馆,有n个顾客站在x轴上不同坐标上且叫了外卖,每个人的脾气不同,每1分钟没有收到外卖就会增加Fi点愤怒值,而外卖小哥的车是有速度的v-1/分钟,问怎样的送餐次序会让所有顾客 ...
随机推荐
- Webpack 3 中的新特性
本文简短地分享下最新发布的 Webpack 3 中的新特性,供大家参考. 1. Webpack 3 的新特性 6 月 20 日,Webpack 发布了最新的 3.0 版本,并在 Medium 发布了公 ...
- Java IO学习笔记三
Java IO学习笔记三 在整个IO包中,实际上就是分为字节流和字符流,但是除了这两个流之外,还存在了一组字节流-字符流的转换类. OutputStreamWriter:是Writer的子类,将输出的 ...
- 纯CSS3美化单选按钮radio
这种纯CSS3美化单选按钮radio的方法适用于以下情况: 1.可兼容IE9以上,需要兼容IE8的要写IE的hack把样式去掉 2.只支持单选按钮radio,因为单选按钮选中样式的圆圈可以用CSS做出 ...
- 教你轻轻松松入门PHP
入门PHP不用愁,跟我来学一学. 1.我们想学习PHP,首先就要了解PHP,那PHP是什么呢? PHP("PHP: Hypertext Preprocessor",超文本预处理器的 ...
- test_markdown
add modifications 非科学计数法显示数字 citation[^ref1] format bank% do not use scientific expression format lo ...
- [leetcode-516-Longest Palindromic Subsequence]
Given a string s, find the longest palindromic subsequence's length in s. You may assume that the ma ...
- JavaScript中的排序
<script> //1. 冒泡排序 function bubbleSort(arr) { var len = arr.length; for (var i = 0; i < len ...
- Backbone中父子view之间的值传递
backbone中,使用最多的莫过于在view中进行操作,如模板的渲染以及事件函数的定义.为了提高代码的可维护性,一般地我们会写多个视图即view,将界面按照功能的不同进行模块化划分,模块与view一 ...
- 浅入深出之Java集合框架(下)
Java中的集合框架(下) 由于Java中的集合框架的内容比较多,在这里分为三个部分介绍Java的集合框架,内容是从浅到深,哈哈这篇其实也还是基础,惊不惊喜意不意外 ̄▽ ̄ 写文真的好累,懒得写了.. ...
- mysql中exists、not exists的用法
exists 关键字是判断是否存在的,存在则返回true,不存在则返回false, not exists则是不存在时返回true,存在返回false: 1. 最常用的if not exists用法: ...