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 Nlines 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
题目大意:
在一个一维坐标轴上,有若干个点,已知餐厅的位置,以及外卖员的速度,不满意度为Bi*等待的时间,求外卖员从餐厅送到各个点的最小总不满意度。
可以将餐厅加进去并排列,以餐厅为中心,向外扩:
dp[i][j][0]:(需要将除了区间以内的数全部乘上这个差值)
dp[i+1][j][0]+(pre[i]+pre[n]-pre[j])*(a[i+1].x-a[i].x) 、dp[i+1][j][1]+(pre[i]+pre[n]-pre[j])*(a[j].x-a[i].x)
dp[i][j][1]:
dp[i][j-1][0]+(pre[i-1]+pre[n]-pre[j-1])*(a[j].x-a[i].x)、dp[i][j-1][1]+(pre[i-1]+pre[n]-pre[j-1])*(a[j].x-a[j-1].x)
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int INF=0x3f3f3f3f;
long long dp[][][],pre[];
int n,v,x;
struct p
{
int x,b;
}a[];
bool cmp(p a,p b)
{
return a.x<b.x;
}
int main()
{
ios::sync_with_stdio(false);
while(cin>>n>>v>>x)
{
memset(dp,INF,sizeof dp);
for(int i=;i<n;i++)
cin>>a[i].x>>a[i].b;
a[n].x=x,a[n].b=;///将餐厅点加进去
sort(a,a+n+,cmp);
int pos=;///找到餐厅的位置
for(int i=;i<=n;i++)
if(a[i].x==x&&a[i].b==)
pos=i;
dp[pos][pos][]=dp[pos][pos][]=;
pre[]=a[].b;
for(int i=;i<=n;i++)///处理前缀和
pre[i]=pre[i-]+a[i].b;
for(int i=pos;i>=;i--)
for(int j=pos;j<=n;j++)
{
if(i==j) continue;
dp[i][j][]=min(dp[i][j][],dp[i+][j][]+(pre[i]+pre[n]-pre[j])*(a[i+].x-a[i].x));///左,前左
dp[i][j][]=min(dp[i][j][],dp[i+][j][]+(pre[i]+pre[n]-pre[j])*(a[j].x-a[i].x));///左,前右
dp[i][j][]=min(dp[i][j][],dp[i][j-][]+(pre[i-]+pre[n]-pre[j-])*(a[j].x-a[i].x));///右,前左
dp[i][j][]=min(dp[i][j][],dp[i][j-][]+(pre[i-]+pre[n]-pre[j-])*(a[j].x-a[j-].x));///右,前右
}
cout<<v*min(dp[][n][],dp[][n][])<<'\n';///v代表的是每米花多少时间
}
return ;
}
Food Delivery (区间DP)的更多相关文章
- 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 3469 Food Delivery 区间DP
这道题我不会,看了网上的题解才会的,涨了姿势,现阶段还是感觉区间DP比较难,主要是太弱...QAQ 思路中其实有贪心的意思,n个住户加一个商店,分布在一维直线上,应该是从商店开始,先向两边距离近的送, ...
- ZOJ3469 Food Delivery 区间DP
题意:有一家快餐店送外卖,现在同时有n个家庭打进电话订购,送货员得以V-1的速度一家一家的运送,但是每一个家庭都有一个不开心的值,每分钟都会增加一倍,值达到一定程度,该家庭将不会再订购外卖了,现在为了 ...
- 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 + 提前计算费用
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个客人,每个客人每分钟增加的愤怒值不同. ...
- 区间DP小结
也写了好几天的区间DP了,这里稍微总结一下(感觉还是不怎么会啊!). 但是多多少少也有了点感悟: 一.在有了一点思路之后,一定要先确定好dp数组的含义,不要模糊不清地就去写状态转移方程. 二.还么想好 ...
- ZOJ 3469 Food Delivery(区间DP)
https://vjudge.net/problem/ZOJ-3469 题意:在一条直线上有一个餐厅和n个订餐的人,每个人都有随时间上升的不满意值,从餐厅出发,计算出送完时最小的不满意值总和. 思路: ...
- [kuangbin带你飞]专题二十二 区间DP
ID Origin Title 17 / 60 Problem A ZOJ 3537 Cake 54 / 105 Problem B LightOJ 1422 Hallowee ...
随机推荐
- 快速分页:jsp标签pager-taglib
一:简介 Pager-taglib,支持多种风格的分页显示.实际上它是一个Jsp标签库,为在JSP上显示分页信息而设计的一套标签,通过这些标签的不同的组 合,会形成多种不一样的分页页面,风格各异.它既 ...
- UESTC - 878 温泉旅店 二维费用背包问题
http://acm.uestc.edu.cn/#/problem/show/878 设dp[i][j][k]表示在前i个数中,第一个得到的异或值是j,第二个人得到的异或值是k的方案数有多少种. 因为 ...
- Varnish快速安装及测试
实验环境: slave-147: 192.168.75.147 slave-148: 192.168.75.148 两台机器均已关闭selinux,关闭iptables. varnish部署 ...
- sql server group by 分组带sum avg求和需要注意的一点
这是在写SQL语句遇到的一个sum 和group bu分组的问题
- laravel的scout包安装及laravel-es包安装
安装laravel/scout 作用:搜索驱动,可随时更换驱动,上层业务逻辑可不用改变 官网文档:https://laravel-china.org/docs/laravel/5.4/scout/12 ...
- js获取上周、本周、下周的时间
//获取上周起始时间结束时间.下周起始时间结束时间开始时间和本周起始时间结束时间;(西方) function getTime(n) { var now = new Date(); var year = ...
- RGB颜色空间、色调、饱和度、亮度,HSV颜色空间详解
本文章会详细的介绍RGB颜色空间与RGB三色中色调.饱和度.亮度之间的关系,最后会介绍HSV颜色空间! RGB颜色空间 概述 RGB颜色空间以R(Red:红).G(Green:绿).B(Blue:蓝) ...
- Python3简明教程(十四)—— Collections模块
collections 是 Python 内建的一个集合模块,提供了许多有用的集合类. 在这个实验我们会学习 Collections 模块.这个模块实现了一些很好的数据结构,它们能帮助你解决各种实际问 ...
- Vue 在beaforeCreate时获取data中的数据
众所周知,vue在beforecreate时期是获取不到data中的 数据的 但是通过一些方法可以实现在beforecreate时获取到data中的数据 暂时想到两种放发可以实现,vue在before ...
- CPP-基础:快速排序
快速排序(Quicksort)是对冒泡排序的一种改进. 它的基本思想是:通过一趟排序将要排序的数据分割成独立的两部分,其中一部分的所有数据都比另外一部分的所有数据都要小,然后再按此方法对这两部分数据分 ...