C. Basketball Exercise

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. 2⋅n2⋅n students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly nn people in each row). Students are numbered from 11 to nn in each row in order from left to right.

Now Demid wants to choose a team to play basketball. He will choose players from left to right, and the index of each chosen player (excluding the first one taken) will be strictly greater than the index of the previously chosen player. To avoid giving preference to one of the rows, Demid chooses students in such a way that no consecutive chosen students belong to the same row. The first student can be chosen among all 2n2n students (there are no additional constraints), and a team can consist of any number of students.

Demid thinks, that in order to compose a perfect team, he should choose students in such a way, that the total height of all chosen students is maximum possible. Help Demid to find the maximum possible total height of players in a team he can choose.

Input

The first line of the input contains a single integer nn (1≤n≤1051≤n≤105) — the number of students in each row.

The second line of the input contains nn integers h1,1,h1,2,…,h1,nh1,1,h1,2,…,h1,n (1≤h1,i≤1091≤h1,i≤109), where h1,ih1,i is the height of the ii-th student in the first row.

The third line of the input contains nn integers h2,1,h2,2,…,h2,nh2,1,h2,2,…,h2,n (1≤h2,i≤1091≤h2,i≤109), where h2,ih2,i is the height of the ii-th student in the second row.

Output

Print a single integer — the maximum possible total height of players in a team Demid can choose.

Examples
input

Copy
5
9 3 5 7 3
5 8 1 4 5
output

Copy
29
input

Copy
3
1 2 9
10 1 1
output

Copy
19
input

Copy
1
7
4
output

Copy
7
Note

In the first example Demid can choose the following team as follows:

In the second example Demid can choose the following team as follows:

题意:每行输入n个数,一共两行,取过一个数之后,不能再取和它相邻的数(不包括对角相邻),问取数总和最大为多少

题解:状态转移方程:dp[0][i]=max( dp[0][i] , dp[1][i-1]+a[i] );

dp[1][i]=max( dp[1][i] , dp[0][i-1]+b[i] );

#include<iostream>
#include<algorithm>
#include<math.h>
#define ll long long
using namespace std;
ll dp[][],a[],b[];
ll n;
int main()
{
ll n;
cin>>n;
for(int i=;i<n;i++)
scanf("%lld",&a[i]);
for(int i=;i<n;i++)
scanf("%lld",&b[i]);
dp[][]=a[];
dp[][]=b[];
for(int i=;i<n;i++)
{
dp[][i]=max(dp[][i-],dp[][i-]+a[i]);
dp[][i]=max(dp[][i-],dp[][i-]+b[i]);
}
ll ans=max(dp[][n-],dp[][n-]);
printf("%lld\n",ans );
return ;
}

C. Basketball Exercise dp的更多相关文章

  1. Codeforces Round #304 (Div. 2) C. Basketball Exercise (DP)

    题意:给你两个长度相同的数组,每次从两个数组中选数(也可以不选),但是不可以在同一个数组中连续选两次,问能选的最大值是多少? 题解:dp,\(dp[i][0]\)表示第\(i\)个位置不选,\(dp[ ...

  2. CF1195C Basketball Exercise (dp + 贪心)

    题解出处:https://www.luogu.org/problemnew/solution/CF1195C 很水的一道C题……目测难度在黄~绿左右.请各位切题者合理评分. 注意到可以选择的球员编号是 ...

  3. Codeforces Round #574 (Div. 2)——C. Basketball Exercise(简单DP)

    题目传送门 题意: 输入n,给出两组均为 n个数字的数组a和b,轮流从a和b数组中取出一个数字,要求严格按照当前所选数字的数组下标比上一个所选数字的数组下标更大,计算能够取出的数字加起来的总和最大能为 ...

  4. Codeforces Round #574 (Div. 2)补题

    A. Drinks Choosing 统计每种酒有多少人偏爱他们. ki 为每种酒的偏爱人数. 输出ans = (n + 1)/2 >  Σki / 2 ? (n + 1)/2 - Σki / ...

  5. 第9周cf刷题(dp)

    Problems(1300-1600) an ac a day keeps the doctor away Gas Pipeline (1500) 2019.10.28 题意: 管道工人需要在一段凹凸 ...

  6. Codeforce Round #574(Div.2)

                                                                                                        ...

  7. Codeforces Round #574 (Div. 2)

    目录 Contest Info Solutions A. Drinks Choosing B. Sport Mafia C. Basketball Exercise D1. Submarine in ...

  8. Codeforces Round #574 (Div. 2) A~E Solution

    A. Drinks Choosing 有 $n$ 个人,每个人各有一种最喜欢的饮料,但是买饮料的时候只能同一种的两个两个买(两个一对) 学校只打算卖 $\left \lceil \frac{n}{2} ...

  9. BZOJ_2097_[Usaco2010 Dec]Exercise 奶牛健美操_二分答案+树形DP

    BZOJ_2097_[Usaco2010 Dec]Exercise 奶牛健美操_二分答案+树形DP Description Farmer John为了保持奶牛们的健康,让可怜的奶牛们不停在牧场之间 的 ...

随机推荐

  1. SRS源码——UDP

    srs_app_server.cpp  int SrsServer::listen() { int ret = ERROR_SUCCESS; if ((ret = listen_rtmp()) != ...

  2. axios发送post请求[body-parser]--['Content-type': 'application/x-www-form-urlencoded']

    const express = require('express') const axios = require('axios') const bodyParser = require('body-p ...

  3. linux kill命令以及 信号

    kill命令介绍 命令作用 终止一个进程 语法: kill [-s signal|-p] [-q sigval] [-a] [--] pid... kill -l [signal] 选项 -l 信号, ...

  4. vh搭配vw进行响应式布局

    1.浏览器兼容性: IE8-不支持,IOS7.1-不支持,android4.3-不支持 2. vh代表浏览器视口高度(100vh等于当前浏览器的整个高度) 3.vw代表浏览器视口的宽度 (100vw等 ...

  5. jwt 认证

    目录 jwt 认证示意图 jwt 认证算法:签发与检验 drf 项目的 jwt 认证开发流程(重点) drf-jwt 框架基本使用 token 刷新机制(了解) jwt 认证示意图 jwt 优势 1 ...

  6. 四、spring集成ibatis进行项目中dao层基类封装

    Apache iBatis(现已迁至Google Code下发展,更名为MyBatis)是当前IT项目中使用很广泛的一个半自动ORM框架,区别于Hibernate之类的全自动框架,iBatis对数据库 ...

  7. Day9 - H - 最少拦截系统 HDU - 1257

    某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天,雷达捕捉到敌国的导弹来袭.由于 ...

  8. python获取最大、最小值

    1.获取数组极值,并返回索引 c = [-10,-5,0,5,3,10,15,-20,25]   print c.index(min(c)) # 返回最小值 print c.index(max(c)) ...

  9. java文件相关(文件追加内容、文件内容清空、文件内容读取)

    https://blog.csdn.net/xnz0616/article/details/39137177 1.文件内容追加 // 在已有的文件后面追加信息 public static void a ...

  10. sklearn实现多分类逻辑回归

    sklearn实现多分类逻辑回归 #二分类逻辑回归算法改造适用于多分类问题1.对于逻辑回归算法主要是用回归的算法解决分类的问题,它只能解决二分类的问题,不过经过一定的改造便可以进行多分类问题,主要的改 ...