博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Basketball Exercise CodeForces - 1195C(动态规划dp)
阅读量:4135 次
发布时间:2019-05-25

本文共 2388 字,大约阅读时间需要 7 分钟。

Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. 2⋅n students have come to Demid’s exercise session, and he lined up them into two rows of the same size (there are exactly n people in each row). Students are numbered from 1 to n 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 2n 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 n (1≤n≤105) — the number of students in each row.

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

The third line of the input contains n integers h2,1,h2,2,…,h2,n (1≤h2,i≤109), where h2,i is the height of the i-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
5
9 3 5 7 3
5 8 1 4 5
Output
29
Input
3
1 2 9
10 1 1
Output
19
Input
1
7
4
Output
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:

在这里插入图片描述
dp题,对于当前位置有两种可能会转移到这里来。
状态转移方程:
dp[i][1]=max(dp[i-1][0]+a[i],dp[i-1][1]);
dp[i][0]=max(dp[i-1][1]+b[i],dp[i-1][0]);
两种状态
代码如下:

#include
#define ll long longusing namespace std;const int maxx=1e5+100;ll a[maxx],b[maxx];ll dp[maxx][2];int n;int main(){ while(~scanf("%d",&n)) { for(int i=1;i<=n;i++) scanf("%I64d",&a[i]); for(int i=1;i<=n;i++) scanf("%I64d",&b[i]); for(int i=1;i<=n;i++) { dp[i][1]=max(dp[i-1][0]+a[i],dp[i-1][1]); dp[i][0]=max(dp[i-1][1]+b[i],dp[i-1][0]); } cout<
<

比较简单的dp题

努力加油a啊,(o)/~

转载地址:http://dfxvi.baihongyu.com/

你可能感兴趣的文章
vue2.* 中 使用socket.io
查看>>
openlayers安装引用
查看>>
js报错显示subString/subStr is not a function
查看>>
高德地图js API实现鼠标悬浮于点标记时弹出信息窗体显示详情,点击点标记放大地图操作
查看>>
初始化VUE项目报错
查看>>
vue项目使用安装sass
查看>>
HTTP和HttpServletRequest 要点
查看>>
在osg场景中使用GLSL语言——一个例子
查看>>
laravel 修改api返回默认的异常处理
查看>>
laravel事务
查看>>
【JavaScript 教程】浏览器—History 对象
查看>>
还不会正则表达式?看这篇!
查看>>
100道+ JavaScript 面试题,助你查漏补缺
查看>>
JavaScript深入理解之闭包
查看>>
这才是学习Vite2的正确姿势!
查看>>
7 个适用于所有前端开发人员的很棒API,你需要了解一下
查看>>
25个构建Web项目的HTML建议,你需要了解一下!
查看>>
【web素材】02-10款大气的购物商城网站模板
查看>>
6种方式实现JavaScript数组扁平化(flat)方法的总结
查看>>
如何实现a===1 && a===2 && a===3返回true?
查看>>