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<bits/stdc++.h>
#define ll long long
using 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<<max(dp[n][0],dp[n][1])<<endl;}
}

比较简单的dp题
努力加油a啊,(o)/~

Basketball Exercise CodeForces - 1195C(动态规划dp)相关推荐

  1. 1195C. Basketball Exercise

    C. Basketball Exercise:题目 经典简单dp,考虑前两天的就行 #include <bits/stdc++.h> using namespace std; typede ...

  2. C. Basketball Exercise dp

    C. Basketball Exercise time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  3. 【CF 1195】Basketball Exercise/Submarine in the Rybinsk Sea (hard edition)/OpenStreetMap+二维单调队列滑动窗口模板

    寡人认为C,E都是比较板的题 butD2也太ex了,大大是被那个mod精给弄疯了,我mod了那么多次还是炸了longlong orz 文章目录 二维单调队列模板 C:Basketball Exerci ...

  4. 第4课 防卫导弹(第十章 动态规划--DP)

    //progream p10_04 /* 第4课 防卫导弹(第十章 动态规划--DP)  (<聪明人的游戏--信息学探秘 提高篇>) https://blog.csdn.net/weixi ...

  5. 动态规划dp(带模板题の超易懂版):01背包,完全背包,分组背包,多重背包,混合背包

    动态规划dp(带模板题の超易懂版):01背包,完全背包,分组背包,多重背包 01背包 && 完全背包 && 分组背包 の 视频教程:https://www.bilibi ...

  6. 【习题详解】动态规划DP:硬币游戏 蛋糕 游荡的奶牛 决斗

    动态规划DP 硬币 蛋糕塔 游荡的奶牛 格斗 硬币 题目描述 农夫约翰的奶牛喜欢玩硬币游戏,因此他发明了一种称为"Xoinc"的两人硬币游戏. 初始时,一个有N(5 <= N ...

  7. 动态规划: dp+递推——确定动态矩阵dp含义,确定每个状态下面临的选择和对结果值影响,选择符合题意的作为结果存储在dp中

    1.动态规划:每一个状态一定是由之前的状态推导出来的,通过总结归纳发现递推关系 2.解决动态规划问题的步骤: 确定dp数组(dp table)以及下标的含义: 每个单元内 题目所求的值,一维.二维 确 ...

  8. CodeForces - 1497D Genius(dp)

    题目链接:点击查看 题目大意:给出 nnn 个问题,每个问题有如下属性: tagtagtag:标签 ccc:困难度 sss:奖励值 初始时 ci=2ic_i=2^ici​=2i,初始时 IQ=0IQ= ...

  9. Datawhale编程——动态规划DP

    0-1背包问题 问题:有n个物品,第i个物品价值为vi,重量为wi,其中vi和wi均为非负数,背包的容量为W,W为非负数.现需要考虑如何选择装入背包的物品,使装入背包的物品总价值最大. 针对这个经典的 ...

最新文章

  1. 为什么要使用sigmoid,tanh,ReLU等非线性函数?
  2. Spring Cloud + Mybatis配置类设置
  3. 可以从max中导出静态模型并渲染了。
  4. Netty之粘包分包
  5. hi3516配置wifi_HISI 3516A移植mt7601u的wifi驱动
  6. SVN 清理失败解决方案
  7. MySQL不能使用/tmp
  8. SCSI子系统(一)
  9. 世界各国与中国时差查询
  10. 《那些年啊,那些事——一个程序员的奋斗史》——101
  11. oracle创建完成 sys密码怎么修改,如何重置密码 oracle sys和system
  12. 单片机复位电路的可靠性设计及精典实用复位电路
  13. sql注入风险和案例分析
  14. C措辞教程第二章: 数据范例、运算符、表达式(4)
  15. 基于Java+SpringBoot+Thymeleaf+Mysql医院预约挂号系统设计与实现
  16. 喜讯!清华大学镜像站恢复anaconda加速
  17. 入手一年,再谈HiFi耳机的“白月光”——飞利浦Fidelio X3
  18. Ubuntu18.04 编译报错 `No package ‘orocos-bfl‘ found` 的解决方法
  19. 推荐系统(八)FNN模型(FM+MLP=FNN)
  20. python写BMI计算器

热门文章

  1. IOS中的枚举的写法...
  2. python一到10整数的平方和_零基础学python_10_列表(创建数值列表 )
  3. python设计大赛_GitHub - FatBallFish/Multimedia-Python: 多媒体设计大赛-Python后端
  4. 浮点数可以直接相加么?_鸭粪屎可以直接做有机肥么?
  5. js 延迟几秒执行_深入研究 Node.js 的回调队列
  6. oracle的pdb,oracle pdb基本管理
  7. 倒立摆自动起摆_今天起,中山街坊可以去唱K、游泳、看电影、摆喜酒了!
  8. custompage.width 不能小数吗_基金净值暴涨暴跌,背后的原因你清楚吗?
  9. 中国石油计算机第二次在线作业,中国石油大学(北京)计算机应用基础第二次在线作业1教程.docx...
  10. linux ping不允许的操作,linux – ping:sendmsg:不允许操作(有时)