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应用 ...
随机推荐
- hdu 4849
简单题,公式计算+最短路.注意点:注意1 取模,2 数组开到n*n+n. #include<iostream> #include<queue> using namespace ...
- AC日记——[USACO1.5]数字三角形 Number Triangles 洛谷 P1216
题目描述 观察下面的数字金字塔. 写一个程序来查找从最高点到底部任意处结束的路径,使路径经过数字的和最大.每一步可以走到左下方的点也可以到达右下方的点. 7 3 8 8 1 0 2 7 4 4 4 5 ...
- (3)Swing常用组件
JTextField-文本框 继承自javax.swing.text.JTextComponent类
- Win10激活Office2013的技巧
原文:http://www.xitongzhijia.net/xtjc/20150720/53252.html KMSpico Win10激活工具 是一款能激活Win8/Win8.1/win10/Of ...
- CloudStack系统虚拟机启动但不在Host表中
有网友问到这个问题,CloudStack中,系统虚拟机正常启动,Running状态. 可是在host表中没有对应项,上传下载模板等功能也不正常. 原因:系统虚拟机启动之后,会通过管理网段主动连接man ...
- Redis java使用
直接应用redis.clients:jedis的jar包到项目中,然后直接就可以使用,具体对五种类型的数据操作方法,可以翻代码找到. 连接到 redis 服务 实例 import redis.clie ...
- sed 常用命令
删除以ifeq开头的行 sed -i "/^ifeq/d" file 删除空行 sed -i '/^$/d' file
- 从.Net版本演变看String和StringBuilder性能之争
在C#中string关键字的映射实际上指向.NET基类System.String.System.String是一个功能非常强大且用途非常广泛的基类,所以我们在用C#string的时候实际就是在用.NE ...
- 获取Wifi密码,不知道是不是真的
package com.example.wifipassword; import java.util.List; import android.app.Activity; import android ...
- js之substr和substring的差别
今天有人在群里问这两个的差别,借这个机会在这罗列下 substring(from,to) 開始和结束的位置,从零開始的索引 參数 描写叙述 from 必需. 一个非负的整数,规定要提取 ...