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.

  在一条蛋疼的河两旁有一些景点。河左边有N个景点,河右边有M个景点。在河上搭着一些桥沟通两岸的景点(桥是无向的),但是在河的同一边的景点之间都有参天的大树阻拦着,无法通行。我们从河的上游往下游按顺序把景点编上号。目前我们要设计1条路线,可以从河岸任意一边的任意一个景点开始到河岸任意一边的任意一个景点结束。这条路线必须要满足其中没有桥交叉。我们对于交叉的定义如下:对于a<->x和b<->y两座桥,若(a<b && x>y) || (a>b && x<y) || (a=b && x=y),则这两座桥交叉。满足上面的条件之后,开始提问了:已知每个景点都有一个美丽值,你设计的路线必须满足其美丽值最大。那么最大的美丽值是多少?

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

3 2 4
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

8
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的更多相关文章

  1. Usaco2012-2013 金组 题解 (暂缺Hill walk以及Figue eight)

    https://files.cnblogs.com/files/Winniechen/usaco2012-2013.pdf 做的不是很好,还请见谅! 如果有什么疑问,可以QQ上找我. QQ号:1967 ...

  2. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  3. bzoj 4097: [Usaco2013 dec]Vacation Planning

    4097: [Usaco2013 dec]Vacation Planning Description Air Bovinia is planning to connect the N farms (1 ...

  4. Application Request Route实现IIS Server Farms集群负载详解

    序言 随着公司业务的发展,后台业务就变的越来越多,然而服务器的故障又像月经一样,时不时的汹涌而至,让我们防不胜防.那么后台的高可用,以及服务器的处理能力就要做一个横向扩展的方案,以使后台业务持续的稳定 ...

  5. .net core 源码解析-mvc route的注册,激活,调用流程(三)

    .net core mvc route的注册,激活,调用流程 mvc的入口是route,当前请求的url匹配到合适的route之后,mvc根据route所指定的controller和action激活c ...

  6. angular路由——ui.route

    angular路由 使用案例 <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...

  7. 如何在ARM中创建Express Route

    很早之前就想试试Azure的express route,但是一直没有找到合适的机会,正好有个客户需要上express route,所以最近先自己研究研究,防止在做poc的时候耗费更多时间,本次场景我们 ...

  8. Python flask @app.route

    转载自 http://python.jobbole.com/80956/ 下面是Flask主页给我们的第一个例子,我们现在就由它入手,深入理解“@app.route()”是如何工作的.         ...

  9. AngularJS中的route可以控制页面元素的改变,使多页面变成一个单页面。。。

    SPA(Single Page Application)指的是通单一页面展示所有功能,通过Ajax动态获取数据然后进行实时渲染,结合CSS3动画模仿原生App交互,然后再进行打包(使用工具把Web应用 ...

随机推荐

  1. Java下接口interface前面要不要加I

    说明:加I和不加I都可以,看需要,没有强制要求. 在Java中更多是提倡不加I的,可以看下JDK的源码,都是不加I的. 微软C#是规定要加I,这也是影响从而导致有这个话题的原因. Java中特定不直接 ...

  2. 前端和后端采用接口访问时的调用验证机制(基于JWT的前后端验证)(思路探讨)

    说明:基于前后端,尤其是使用Ajax请求的接口,现在市面上网页上调用的Ajax基本都是没有验证的,如果单独提取之后可以无线的刷数据. 继上一篇http://www.cnblogs.com/EasonJ ...

  3. BUPT复试专题—树查找(2011)

    https://www.nowcoder.com/practice/9a10d5e7d99c45e2a462644d46c428e4?tpId=67&tqId=29641&rp=0&a ...

  4. BeagleBone Black Industrial 工业版介绍

    前言 在电子发烧友论坛看到有Beaglebone Black Industrial版的试用,这里介绍一下这块开发板. BBB是开源硬件,原理图.BOM等都开放下载,所以也有诸多兼容板. BBB兼容产品 ...

  5. C#中Queue&lt;T&gt;类的使用以及部分方法的源代码分析

    Queue<T>类 表示对象的先进先出集合. 队列在按接收顺序存储消息方面很实用,以便于进行顺序处理. 存储在 Queue,<T> 中的对象在一端插入,从还有一端移除. Que ...

  6. HDU oj 开门人与关门人

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1234 #include<stdio.h> #include<string.h> ...

  7. react 创建组件 (二)component

    因为ES6对类和继承有语法级别的支持,所以用ES6创建组件的方式更加优雅,下面是示例: import React from 'react'; class Greeting extends React. ...

  8. Maven实现Web应用集成測试自己主动化 -- 測试自己主动化(WebTest Maven Plugin)

    近期在appfuse看到使用webtest-maven-plugin实现Web应用的集成測试,研究了下.感觉很不错.对于Web应用自己主动构建很有帮助,在性能測试之前能够保证Web应用的基本功能工作正 ...

  9. HDU1114 Piggy-Bank 【全然背包】

    Piggy-Bank Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total ...

  10. IntelliTrace窗口无法弹出的解决办法

    最近在使用EF框架,所以需要IntelliTrace窗口进行对ADO的SQL生成监控.可找了半天都无法Call出该窗口. 在Debug模式下,选择调试->窗口 里面根本没有IntelliTrac ...