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[2][100005],a[100005],b[100005];
ll n;
int main()
{ll n;cin>>n;for(int i=0;i<n;i++)scanf("%lld",&a[i]);for(int i=0;i<n;i++)scanf("%lld",&b[i]);dp[0][0]=a[0];dp[1][0]=b[0];for(int i=1;i<n;i++){dp[0][i]=max(dp[0][i-1],dp[1][i-1]+a[i]);dp[1][i]=max(dp[1][i-1],dp[0][i-1]+b[i]);}ll ans=max(dp[0][n-1],dp[1][n-1]);printf("%lld\n",ans );return 0;
}

转载于:https://www.cnblogs.com/-citywall123/p/11207978.html

C. Basketball Exercise dp相关推荐

  1. Basketball Exercise CodeForces - 1195C(动态规划dp)

    Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exerci ...

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

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

  3. 1195C. Basketball Exercise

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

  4. SEON - 1 怒怼Dp(1)

    关于标题 (S)Serious(E)Exercise(O)Of(N)Noip 怒怼Dp系列 T1 题目背景: HDU 1158 Employment Planning 解题报告: -一个比较简单且暴力 ...

  5. dp,sp,px相互转化

    方法一: public int sp2px(float sp) {return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, ...

  6. [JS][dp]题解 | #打家劫舍(一)#

    题解 | #打家劫舍(一)# 题目链接 打家劫舍(一) 题目描述 描述 你是一个经验丰富的小偷,准备偷沿街的一排房间,每个房间都存有一定的现金,为了防止被发现,你不能偷相邻的两家,即,如果偷了第一家, ...

  7. HDU 2084 数塔(DP)(JAVA版)

    数塔 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...

  8. dp cf 20190615

    A. Timofey and a tree 这个不算是dp,就是一个思维题,好难想的思维题,看了题解才写出来的, 把点和边分开,如果一条边的两个点颜色不同就是特殊边,特殊边两边连的点就叫特殊点, 如果 ...

  9. BZOJ 1003[ZJOI2006]物流运输(SPFA+DP)

    Problem 1003. -- [ZJOI2006]物流运输 1003: [ZJOI2006]物流运输 Time Limit: 10 Sec  Memory Limit: 162 MB Submit ...

最新文章

  1. java se 与j2se_关于java:J2EE和J2SE项目之间的区别
  2. linux tcp阻塞socket recv接收数据 未达到指定长度返回问题
  3. Emacs-小白入坑之旅
  4. $.ajax防止多次点击重复提交的方法
  5. 【SDOI 2011】Paint 染色
  6. [编程技巧] C++字符串初始化的优化写法
  7. eclipse启动时JDK环境变量报错
  8. declare sql语句_SQL高级知识——动态SQL
  9. 剑指offer--矩阵中的路径
  10. [转]给新同学的礼仪建议
  11. java后根次序非递归输出_求根结点到每个叶子节点的逆序列【后序遍历非递归的应用】...
  12. Linux必会100个命令(八)ps、top、netstat
  13. 教你用Axure绘制三级菜单
  14. IAR For ARM 7.8下载地址
  15. HTML5已定稿:将彻底颠覆原生应用
  16. 今天才发现!通过微信左下角,还可以快速找到未读消息
  17. opencv android安装教程,opencv for android安装教程.doc
  18. Weakly-Supervised Physically Unconstrained Gaze Estimation论文翻译
  19. 阿里云redis学习笔记
  20. python判断纯英文和纯数字

热门文章

  1. aws lambda使用_使用AWS Lambda,无服务器框架和Go的按需WebSockets
  2. 近几年一直流行说的DSP具体是什么,为什么大家都在关注
  3. 未在服务器上找到sql安装程序文件,MS SQL Server 2000/以前的某个程序安装已在安装计算机上创建挂起的文件操作。...
  4. 商业数据分析【一】概述及职业发展
  5. Nginx 理论+实例超详细讲解
  6. 稳稳压二极管原理及主要参数
  7. 简述TCP的流量控制与拥塞控制
  8. Android Studio 从入门到精通视频教程
  9. c语言程序设计理论考试,《C语言程序设计》理论试题库-程序题100例
  10. 西安国微EDA研发中心正式启动运营;2020上半年10大典型工业网络安全事件 | 美通企业日报...