BZOJ_3063_[Usaco2013]Route Designing_DP
BZOJ_3063_[Usaco2013]Route Designing_DP
Description
After escaping from the farm, Bessie has decided to start a travel agency along the Amoozon river. There are several tourist sites located on both sides of the river, each with an integer value indicating how interesting the tourist site is. Tourist sites are connected by routes that cross the river (i.e., there are no routes connecting a site with a site on the same side of the river). Bessie wants to design a tour for her customers and needs your help. A tour is a sequence of tourist sites with adjacent sites connected by a route. In order to best serve her customers she wants to find the route that maximizes the sum of the values associated with each visited site. However, Bessie may be running several of these tours at the same time. Therefore it's important that no two routes on a tour intersect. Two routes (a <-> x) and (b <-> y) intersect if and only if (a < b and y < x) or (b < a and x < y) or (a = b and x = y). Help Bessie find the best tour for her agency. Bessie may start and end at any site on either side of the Amoozon.
Input
* Line 1: Three space separated integers N (1 <= N <= 40,000), M (1 <= M <= 40,000), and R (0 <= R <= 100,000) indicating respectively the number of sites on the left side of the river, the number of sites on the right side of the river, and the number of routes.
* Lines 2..N+1: The (i+1)th line has a single integer, L_i (0 <= L_i <= 40,000), indicating the value of the ith tourist site on the left side of the river.
* Lines N+2..N+M+1: The (i+N+1)th line has a single integer, R_i (0 <= R_i <= 40,000), indicating the value of the ith tourist site on the right side of the river.
* Lines N+M+2..N+M+R+1: Each line contains two space separated integers I (1 <= I <= N) and J (1 <= J <= M) indicating there is a bidirectional route between site I on the left side of the river and site J on the right side of the river.
Output
Line 1: A single integer indicating the maximum sum of values attainable on a tour.
Sample Input
1
1
5
2
2
1 1
2 1
3 1
2 2
INPUT DETAILS: There are three sites on the left side of the Amoozon
with values 1, 1, and 5. There are two sites on the right side of the
Amoozon with values 2 and 2. There are four routes connecting sites on
both sides of the river.
Sample Output
OUTPUT DETAILS: The optimal tour goes from site 1 on the left, site 1 on
the right, and ends at site 3 on the left. These respectively have
values 1, 2, and 5 giving a total value of the trip of 8.
HINT
Left No.1 -> Right No.1 -> Left No.3,答案是1+2+5=8.
把所有边按第一维排序,相等的按第二维排序。
设f[i]表示走到河左边的第i个景点的最大收益,g[i]表示走到河右边的第i个景点的最大收益。
因为已经有序,河左边的在此之前没有被更新过,河右边能更新x的也已经是最优情况,直接转移即可。
代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 100050
#define fs first
#define sd second
#define _max(x,y) ((x)>(y)?(x):(y))
inline char nc() {
static char buf[100000],*p1,*p2;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline int rd() {
int x=0; char s=nc();
while(s<'0'||s>'9') s=nc();
while(s>='0'&&s<='9') x=(x<<3)+(x<<1)+s-'0',s=nc();
return x;
}
int f[40050],g[40050],n,m,q,val[N];
pair<int,int>e[N];
int main() {
n=rd(); m=rd(); q=rd();
int i,ans=0,x,y,tmp;
for(i=1;i<=n;i++) f[i]=val[i]=rd(),ans=_max(ans,f[i]);
for(i=1;i<=m;i++) g[i]=val[i+n]=rd(),ans=_max(ans,g[i]);
for(i=1;i<=q;i++) e[i].fs=rd(),e[i].sd=rd();
sort(e+1,e+q+1);
for(i=1;i<=q;i++) {
x=e[i].fs,y=e[i].sd,tmp=g[y];
g[y]=_max(g[y],f[x]+val[y+n]); f[x]=_max(f[x],tmp+val[x]); ans=_max(ans,max(f[x],g[y]));
}
printf("%d\n",ans);
}
BZOJ_3063_[Usaco2013]Route Designing_DP的更多相关文章
- Usaco2012-2013 金组 题解 (暂缺Hill walk以及Figue eight)
https://files.cnblogs.com/files/Winniechen/usaco2012-2013.pdf 做的不是很好,还请见谅! 如果有什么疑问,可以QQ上找我. QQ号:1967 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- bzoj 4097: [Usaco2013 dec]Vacation Planning
4097: [Usaco2013 dec]Vacation Planning Description Air Bovinia is planning to connect the N farms (1 ...
- Application Request Route实现IIS Server Farms集群负载详解
序言 随着公司业务的发展,后台业务就变的越来越多,然而服务器的故障又像月经一样,时不时的汹涌而至,让我们防不胜防.那么后台的高可用,以及服务器的处理能力就要做一个横向扩展的方案,以使后台业务持续的稳定 ...
- .net core 源码解析-mvc route的注册,激活,调用流程(三)
.net core mvc route的注册,激活,调用流程 mvc的入口是route,当前请求的url匹配到合适的route之后,mvc根据route所指定的controller和action激活c ...
- angular路由——ui.route
angular路由 使用案例 <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...
- 如何在ARM中创建Express Route
很早之前就想试试Azure的express route,但是一直没有找到合适的机会,正好有个客户需要上express route,所以最近先自己研究研究,防止在做poc的时候耗费更多时间,本次场景我们 ...
- Python flask @app.route
转载自 http://python.jobbole.com/80956/ 下面是Flask主页给我们的第一个例子,我们现在就由它入手,深入理解“@app.route()”是如何工作的. ...
- AngularJS中的route可以控制页面元素的改变,使多页面变成一个单页面。。。
SPA(Single Page Application)指的是通单一页面展示所有功能,通过Ajax动态获取数据然后进行实时渲染,结合CSS3动画模仿原生App交互,然后再进行打包(使用工具把Web应用 ...
随机推荐
- ZOJ - 4016 Mergeable Stack (STL 双向链表)
[传送门]http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4016 [题目大意]初始有n个空栈,现在有如下三种操作: (1) ...
- Opengl配置
Opengl配置说明: 本配置文档针对windows64位操作系统,配置vs2008项目工程 1.下载OpenGL的glut类库:http://www.opengl.org/resources/lib ...
- ios下读取jason中的nsstring时间并本地化成中文gmt时间显示上午下午
https://developer.apple.com/library/ios/qa/qa1480/_index.html - (NSDate *)dateFromString:(NSString * ...
- android 获得系统时间
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools= ...
- Apdex——衡量服务器性能的标准
Apdex 全称是 Application Performance Index,是由 Apdex 联盟开放的用于评估应用性能的工业标准.Apdex 联盟起源于 2004 年,由 Peter Sevci ...
- es中插入数据
es中插入数据 学习了:https://www.imooc.com/video/15769/0 分为指定Id和自动生成Id两种: 1,指定Id使用PUT操作 PUT http://127.0.0.1: ...
- C语言的代码内存布局具体解释
一个程序本质上都是由 BSS 段.data段.text段三个组成的.这种概念在当前的计算机程序设计中是非常重要的一个基本概念,并且在嵌入式系统的设计中也非常重要,牵涉到嵌入式系统执行时的内存大小分配, ...
- BeagleBone Black Industrial 进阶设置(性能优化以及延长板载eMMC存储寿命)
前言 原创文章,转载引用务必注明链接.水平有限,欢迎指正. 本文使用markdown写成,为获得更好的阅读体验,推荐访问我的博客原文: http://www.omoikane.cn/2016/09/1 ...
- MAC上Nuclide的安装
MAC上Nuclide的安装 本文版权归作者全部,如需转载请联系孟祥月 CSDN博客:http://blog.csdn.net/mengxiangyue 独立博客:http://mengxiangyu ...
- 【转载】WebService相关概念
一.序言 大家或多或少都听过 WebService(Web服务),有一段时间很多计算机期刊.书籍和网站都大肆的提及和宣传WebService技术,其中不乏很多吹嘘和做广告的成 分.但是不得不承认的是W ...