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. P1111 修复公路 洛谷

    https://www.luogu.org/problem/show?pid=1111 题目背景 A地区在地震过后,连接所有村庄的公路都造成了损坏而无法通车.政府派人修复这些公路. 题目描述 给出A地 ...

  2. hzwer与逆序对

    codevs——4163 hzwer与逆序对 貌似这个题和上个题是一样的((⊙o⊙)…)  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 黄金 Gold 题解       题目 ...

  3. 创建ROS工作空间和包

    一.创建工作空间 mkdir -p ~/openni_ws/src cd ~/openni_ws catkin_make        //在catkin工作空间(openni_ws)下catkin_ ...

  4. Oracle ORA-01033: ORACLE initialization or shutdown in progress

    先说明,我出现此错误的原因是:我手动通过drop语句删除表空间,结果磁盘中文件还存在,然后我手动删除了文件,重启了oracle服务,再去连接oracle时就出现了这个错误. 网上也有“连接Oracle ...

  5. IOS --关于粘贴板 ,剪切板 ,UILabel的复制

    在iOS中下面三个控件,自身就有复制-粘贴的功能: 1.UITextView 2.UITextField 3.UIWebView UIKit framework提供了几个类和协议方便我们在自己的应用程 ...

  6. linux批量解压和批量压缩

    ls *.tar.gz | xargs -n1 tar xzvf //批量解压 ls | awk '{ print "tar zcvf "$0".tar.gz " ...

  7. git 更新远程分支

    使用git的时候,有时候会出现远端更新了一个分支,但是从本地想checkout一个远程分支时,会出现如下错误: fatal: git checkout: updating paths is incom ...

  8. fedora关闭防火墙

    sudo systemctl stop iptables sudo sytemctl stop firewalld

  9. linked-list-cycle-ii——链表,找出开始循环节点

    Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull. Follo ...

  10. JSP简明教程:汇总

    原创JSP教程,简洁明了,不含废话. JSP简明教程(一):JSP简单介绍 JSP简明教程(二):JSP基本的语法 JSP简明教程(三):JSP隐含对象 JSP简明教程(四):EL表达式语言.Java ...