题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4255

题目大意:
在x轴上有n个客人,每个客人每分钟增加的愤怒值不同。给出客人和餐厅的位置,以及客人每分钟增加的愤怒值,
和送餐行走一公里需要的时间,问送完n个客人的外卖最小愤怒值。
解题思路:
如果要访问完[i,j],那么它的子区间一定访问完了。
用dp[i][j][0]表示访问完区间[i,j]并留在左端点,dp[i][j][1]表示访问完区间[i,j]并留在右端点。
把饭店那个地方也加进去作为点。从饭店那个点往两边进行DP;
dp[i][j][0] 可以根据dp[i+1][j][0]和dp[i+1][j][1]得到。
dp[i][j][1] 可以根据dp[i][j-1][0]和dp[i][j-1][1]得到。

代码:

 #include<cstdio>
#include<cmath>
#include<cctype>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<string>
#define lc(a) (a<<1)
#define rc(a) (a<<1|1)
#define MID(a,b) ((a+b)>>1)
#define fin(name) freopen(name,"r",stdin)
#define fout(name) freopen(name,"w",stdout)
#define clr(arr,val) memset(arr,val,sizeof(arr))
#define _for(i,start,end) for(int i=start;i<=end;i++)
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long LL;
const int N=1e3+;
const int INF=0x3f3f3f3f;
const double eps=1e-; struct node{
int x,b;
}p[N];
int sum[N];
int dp[N][N][]; //用dp[i][j][0]表示访问完区间[i,j]并留在左端点,dp[i][j][1]表示访问完区间[i,j]并留在右端点。 bool cmp(node a,node b){
return a.x<b.x;
} int main(){
FAST_IO;
int n,v,st;
while(cin>>n>>v>>st){
for(int i=;i<=n;i++){
cin>>p[i].x>>p[i].b;
}
p[++n].x=st;
p[n].b=;
sort(p+,p++n,cmp);
int pos;
for(int i=;i<=n;i++){
sum[i]=sum[i-]+p[i].b;
if(p[i].x==st)
pos=i;
}
memset(dp,0x3f,sizeof(dp));
dp[pos][pos][]=dp[pos][pos][]=;
for(int i=pos;i>=;i--){
for(int j=pos;j<=n;j++){
if(i==j) continue;
//如果从i+1这个点移动到i花费了时间t,那么除了i等待了t.
//其它所有还没收到午餐的用户也都等待了t,因此要把他们的不满意度都算上
dp[i][j][]=min(dp[i][j][],dp[i+][j][]+(sum[i]+sum[n]-sum[j])*(p[i+].x-p[i].x));
dp[i][j][]=min(dp[i][j][],dp[i+][j][]+(sum[i]+sum[n]-sum[j])*(p[j].x-p[i].x)); dp[i][j][]=min(dp[i][j][],dp[i][j-][]+(sum[i-]+sum[n]-sum[j-])*(p[j].x-p[i].x));
dp[i][j][]=min(dp[i][j][],dp[i][j-][]+(sum[i-]+sum[n]-sum[j-])*(p[j].x-p[j-].x));
}
}
printf("%d\n",v*min(dp[][n][],dp[][n][]));
}
return ;
}

ZOJ 3469 Food Delivery(区间DP好题)的更多相关文章

  1. ZOJ 3469 Food Delivery 区间DP

    这道题我不会,看了网上的题解才会的,涨了姿势,现阶段还是感觉区间DP比较难,主要是太弱...QAQ 思路中其实有贪心的意思,n个住户加一个商店,分布在一维直线上,应该是从商店开始,先向两边距离近的送, ...

  2. zoj 3469 Food Delivery 区间dp + 提前计算费用

    Time Limit: 2 Seconds      Memory Limit: 65536 KB When we are focusing on solving problems, we usual ...

  3. ZOJ - 3469 Food Delivery (区间dp)

    When we are focusing on solving problems, we usually prefer to stay in front of computers rather tha ...

  4. 又一道区间DP的题 -- P3146 [USACO16OPEN]248

    https://www.luogu.org/problemnew/show/P3146 一道区间dp的题,以区间长度为阶段; 但由于要处理相邻的问题,就变得有点麻烦; 最开始想了一个我知道有漏洞的方程 ...

  5. poj 2955 Brackets (区间dp基础题)

    We give the following inductive definition of a “regular brackets” sequence: the empty sequence is a ...

  6. ZOJ 3469 Food Delivery(区间DP)

    https://vjudge.net/problem/ZOJ-3469 题意:在一条直线上有一个餐厅和n个订餐的人,每个人都有随时间上升的不满意值,从餐厅出发,计算出送完时最小的不满意值总和. 思路: ...

  7. ZOJ 3469Food Delivery(区间DP)

    Food Delivery Time Limit: 2 Seconds      Memory Limit: 65536 KB When we are focusing on solving prob ...

  8. ZOJ3469 Food Delivery —— 区间DP

    题目链接:https://vjudge.net/problem/ZOJ-3469 Food Delivery Time Limit: 2 Seconds      Memory Limit: 6553 ...

  9. 状态压缩---区间dp第一题

    标签: ACM 题目 Gappu has a very busy weekend ahead of him. Because, next weekend is Halloween, and he is ...

随机推荐

  1. 【转】了解CNN

    摘要 过去几年,深度学习在解决诸如视觉识别.语音识别和自然语言处理等很多问题方面都表现出色.在不同类型的神经网络当中,卷积神经网络是得到最深入研究的.早期由于缺乏训练数据和计算能力,要在不产生过拟合的 ...

  2. python学习(十八)爬虫中加入cookie

    转载自:原文链接 前几篇文章介绍了urllib库基本使用和爬虫的简单应用,本文介绍如何通过post信息给网站,保存登陆后cookie,并用于请求有权限的操作.保存cookie需要用到cookiejar ...

  3. git更换 拉取推送地址

    更换:git remote set-url originhttp://git.caomall.cn/sucry/mouse.git」

  4. Python【面向对象编程】

    #1.python中,类名首字母都大写#2.在python3中,经典类和新式类没有任何区别#3.在python2中,经典类和新式类的区别主要体现在多继承上,经典类是深度优先,新式类是广度优先#4.在p ...

  5. Java基础-IO流对象之转换流(InputStreamReader与OutoutStreamWriter)

    Java基础-IO流对象之转换流(InputStreamReader与OutoutStreamWriter) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.转换流概述 我们之前 ...

  6. clock()、time()、clock_gettime()和gettimeofday()函数的用法和区别

    1. clock_gettime( ) 提供了纳秒的精确度 int clock_gettime(clockid_t clk_id, struct timespect *tp); clockid_t c ...

  7. java 编码问题

    Java默认使用Unioncode编码,即不论什么语言都是一个字符占两个字节 Java的class文件编码为UTF-8,而虚拟机JVM编码为UTF-16 UTF-8编码下,一个中文占3个字节,一个英文 ...

  8. CF&&CC百套计划1 Codeforces Round #449 B. Ithea Plays With Chtholly

    http://codeforces.com/contest/896/problem/B 题意: 交互题 n张卡片填m个1到c之间的数,1<=n*ceil(c/2)<=m 最后填出一个单调非 ...

  9. TOMCAT添加管理用户认证

    添加配置文件 --原配置文件: # tail -5 /usr/local/tomcat/conf/tomcat-users.xml <user username="tomcat&quo ...

  10. yum安装_yum命令的相关操作

    2017年1月11日, 星期三 yum安装的四种方式 一.默认:从国外下载 二.国内:从阿里获取  http://mirrors.aliyun.com 1. cd /etc/yum.repos.d 2 ...