ZOJ 3469 Food Delivery (区间DP)
来源:互联网 发布:8090端口是干嘛的 编辑:程序博客网 时间:2024/06/05 22:35
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
Author: LI, Cheng
Contest: ZOJ Monthly, February 2011
dp[i][j][[0]表示送完[i,j]区间停在左边,dp[i][j][1]表示送完[i,j]区间停在右边
#include <stdio.h>#include <string.h>#include <algorithm>const int INF=0x3f3f3f3f;using namespace std;int n,v,x;int dp[1010][1010][2],sum[1010];struct po{int x,b;}p[1010];bool cmp(po a,po b){return a.x<b.x;}int main (){int i,j;while(scanf("%d %d %d",&n,&v,&x)!=EOF){memset(sum,0,sizeof(sum));for(i=1;i<=n;i++){scanf("%d %d",&p[i].x,&p[i].b);}p[++n].x=x;p[n].b=0;sort(p+1,p+n+1,cmp);for(i=1;i<=n;i++)sum[i]=sum[i-1]+p[i].b;int st;for(i=1;i<=n;i++){if(p[i].x==x){st=i;break;}}for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)dp[i][j][0]=dp[i][j][1]=INF;dp[st][st][0]=dp[st][st][1]=0;for(i=st;i>=1;i--){for(j=st;j<=n;j++){if(i==j)continue;dp[i][j][0]=min(dp[i][j][0],dp[i+1][j][0]+(sum[n]-sum[j]+sum[i])*(p[i+1].x-p[i].x));dp[i][j][0]=min(dp[i][j][0],dp[i+1][j][1]+(sum[n]-sum[j]+sum[i])*(p[j].x-p[i].x));dp[i][j][1]=min(dp[i][j][1],dp[i][j-1][0]+(sum[n]-sum[j-1]+sum[i-1])*(p[j].x-p[i].x));dp[i][j][1]=min(dp[i][j][1],dp[i][j-1][1]+(sum[n]-sum[j-1]+sum[i-1])*(p[j].x-p[j-1].x));}}printf("%d\n",v*min(dp[1][n][0],dp[1][n][1]));}return 0;}
- ZOJ 3469 Food Delivery / 区间DP
- ZOJ 3469 Food Delivery (区间dp)
- zoj 3469 Food Delivery(区间dp)
- zoj 3469 Food Delivery(区间dp)
- ZOJ 3469 - Food Delivery(区间DP)
- ZOJ 3469 Food Delivery (区间DP)
- ZOJ 3469 Food Delivery -- 区间dp
- zoj 3469 Food Delivery (区间dp)
- ZOJ - 3469 Food Delivery(区间DP)
- ZOJ - 3469 Food Delivery(区间DP)
- ZOJ 3469 Food Delivery(区间DP)
- zoj 3469 Food Delivery 【区间dp】
- zoj 3469 Food Delivery (区间DP)
- ZOJ 3469 Food Delivery(区间DP)
- ZOJ - 3469 Food Delivery 区间DP
- ZOJ 3469Food Delivery(区间DP)
- Zoj 3469 Food Delivery (区间DP)
- ZOJ-3469-Food Delivery(区间DP)
- c#程序在部分电脑运行异常解决方法(System.Runtime.InteropServices.COMException (0x80070422): 无法启动服务)
- hibernate简单应用
- HDU 4417 Super Mario (树状数组 + 离线)
- 问题 D: 地宫取宝
- 12个小球中,有一个小球质量M与其他11个小球不同,只能测试3次,怎么可以找出它?
- ZOJ 3469 Food Delivery (区间DP)
- 【HDU-4135】Co-prime
- CGI详解
- 冒泡排序
- Uva 136 Ugly Numbers(丑数)
- C++ sizeof的使用总结
- 网络协议篇之CWMP协议(一)—— CWMP(TR-069)基础
- 图的割点(简易邻接矩阵)C~
- HDUOJ 1232 畅通工程(并查集)