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/分钟,问怎样的送餐次序会让所有顾客 ...
随机推荐
- 跨域CORS
一.跨域CORS是什么 当一个资源从与该资源本身所在的服务器的域或端口不同的域或不同的端口请求一个资源时,浏览器会发起一个跨域 HTTP 请求.出于安全考虑,浏览器会限制从脚本内发起的跨域HTTP请求 ...
- scala环境配置+hello world!
下载地址: http://www.scala-lang.org/download/ 我下载的是zip 配置环境变量 需要jdk支持,jdk的安装配置此处略过 控制台命令 scala -version ...
- 利用Jsoup包爬取网站内容
一 Jsoup包 下载链接:http://download.csdn.net/detail/u014000832/7994245 二 爬取搜狐新闻网站标题等内容 package com.test1; ...
- B. Karen and Coffee
B. Karen and Coffee time limit per test 2.5 seconds memory limit per test 512 megabytes input standa ...
- 手把手教你从基础学习JQuery
JQuery JQuery 语法 1.jQuery("选择器").action();通过选择器调用事件函数 但jQuery中,jQuery可以用$代替,即$("选择器&q ...
- Linux网络编程客户\服务器设计范式
1.前言 网络编程分为客户端和服务端,服务器通常分为迭代服务器和并发服务器.并发服务器可以根据多进程或多线程进行细分,给每个连接创建一个独立的进程或线程,或者预先分配好多个进程或线程等待连接的请求.今 ...
- Java8 Lambda/Stream使用说明
一.Stream流1. 流的基本概念 1.1 什么是流?流是Java8引入的全新概念,它用来处理集合中的数据,暂且可以把它理解为一种高级集合.众所周知,集合操作非常麻烦,若要对集合进行筛选.投影,需要 ...
- angularJS directive详解(自定义指令)
Angularjs指令定义的API AngularJs的指令定义大致如下 其中return返回的对象包含很多参数,下面一一说明 1.restrict (字符串)可选参数,指明指令在DOM里面以什么形式 ...
- 警惕System.Environment.CurrentDirectory 获取当前目录
最近工作中,要做个客户端提醒的小工具:winform程序自然少不了要读取和应用程序同一个目录的配置文件(不是exe.config文件): 要读取当前应用程序所在目录我立马想到了System.Envir ...
- Ext ApplicationController&ref的使用
Ext ApplicationController&ref的使用 Ext.define('app.controller.ApplicationController', { //继承 Ext.a ...