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/分钟,问怎样的送餐次序会让所有顾客 ...
随机推荐
- SICP-1.4-函数设计
何为好的函数 每个函数只完成一个工作 不要做重复工作 如果你多次复制一段代码块,说明你应该进行函数抽象了 定义一般化函数 避免特例化 函数说明 一般通过三引号说明 help调出函数说明 避免过多的参数 ...
- GitHub:多人协作下的分支处理
GitHub上的团队协作 远程信息 git remote:查看远程库的信息 git remote -v:查看远程库的详细信息 推送分支 git push origin 要推送的分支:比如git pus ...
- Python Click 学习笔记(转)
原文链接:Python Click 学习笔记 Click 是 Flask 的团队 pallets 开发的优秀开源项目,它为命令行工具的开发封装了大量方法,使开发者只需要专注于功能实现.恰好我最近在开发 ...
- ArrayList原理解析
简介 ArrayList就是动态数组,用MSDN中的说法,就是Array的复杂版本,它提供了动态的增加和减少元素,实现了ICollection和IList接口,灵活的设置数组的大小等好处 有图有码 图 ...
- JQuery实战——页面进度条效果
今早逛阮一峰大神的博客 ECMAScript 6 入门 时候看到页面顶部有个进度条显示当前浏览的进度,如图: 顶部进度条会根据当前页面高度进行宽度调整,实战一番,视觉使用animated方法实现.下面 ...
- accp8.0转换教材第7章JavaScript操作DOM对象理解与练习
程序调试,chrome开发人员工具,DOM操作,节点和节点间的关系,节点信息,操作节点,获取元素 一.单词部分 ①alert警告②prompt提示③parentNode父节点④childNode子节点 ...
- servlet+jsp update修改页面的实现,整整搞了两个小时才搞定
package DAO; public class books { private int bid; private String bname; private int booksl; private ...
- 怎样把echarts图表做成响应式的
如果想要把echarts图表给做成响应式的那么就应该用rem 单位,给图表的外围容器设置rem 单位,然后调用jquery 的resize方法,$(window).resize(function(){ ...
- Angular基础(二)
双向数据 利用angular把input框里面的值和h3的值绑定在一起.在input里输入内容,内容会在h3标签里显示出来. 具体效果请看下面代码: <!DOCTYPE html> ...
- 图论基础之Dijkstra算法的初探
图论,顾名思义就是有图有论. 图:由点"Vertex"和边"Edge "组成,且图分为有向图和无向图(本文讨论有向图),之前做毕业设计的 ...