C. Basketball Exercise dp
C. Basketball Exercise
2 seconds
256 megabytes
standard input
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.
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.
Print a single integer — the maximum possible total height of players in a team Demid can choose.
5
9 3 5 7 3
5 8 1 4 5
29
3
1 2 9
10 1 1
19
1
7
4
7
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的更多相关文章
- Codeforces Round #304 (Div. 2) C. Basketball Exercise (DP)
题意:给你两个长度相同的数组,每次从两个数组中选数(也可以不选),但是不可以在同一个数组中连续选两次,问能选的最大值是多少? 题解:dp,\(dp[i][0]\)表示第\(i\)个位置不选,\(dp[ ...
- CF1195C Basketball Exercise (dp + 贪心)
题解出处:https://www.luogu.org/problemnew/solution/CF1195C 很水的一道C题……目测难度在黄~绿左右.请各位切题者合理评分. 注意到可以选择的球员编号是 ...
- Codeforces Round #574 (Div. 2)——C. Basketball Exercise(简单DP)
题目传送门 题意: 输入n,给出两组均为 n个数字的数组a和b,轮流从a和b数组中取出一个数字,要求严格按照当前所选数字的数组下标比上一个所选数字的数组下标更大,计算能够取出的数字加起来的总和最大能为 ...
- Codeforces Round #574 (Div. 2)补题
A. Drinks Choosing 统计每种酒有多少人偏爱他们. ki 为每种酒的偏爱人数. 输出ans = (n + 1)/2 > Σki / 2 ? (n + 1)/2 - Σki / ...
- 第9周cf刷题(dp)
Problems(1300-1600) an ac a day keeps the doctor away Gas Pipeline (1500) 2019.10.28 题意: 管道工人需要在一段凹凸 ...
- Codeforce Round #574(Div.2)
...
- Codeforces Round #574 (Div. 2)
目录 Contest Info Solutions A. Drinks Choosing B. Sport Mafia C. Basketball Exercise D1. Submarine in ...
- Codeforces Round #574 (Div. 2) A~E Solution
A. Drinks Choosing 有 $n$ 个人,每个人各有一种最喜欢的饮料,但是买饮料的时候只能同一种的两个两个买(两个一对) 学校只打算卖 $\left \lceil \frac{n}{2} ...
- BZOJ_2097_[Usaco2010 Dec]Exercise 奶牛健美操_二分答案+树形DP
BZOJ_2097_[Usaco2010 Dec]Exercise 奶牛健美操_二分答案+树形DP Description Farmer John为了保持奶牛们的健康,让可怜的奶牛们不停在牧场之间 的 ...
随机推荐
- 名称空间using namespace std
写再最前面:摘录于柳神的笔记 虽然C++是一门面向对象语言,但是对于刷算法这件事而言,我们并不需要掌握它⾯向对象的部分-只 需要掌握刷算法的时候需要用到的部分(基本输⼊输出.STL标准模板库. str ...
- python中numpy.concatenate()函数的使用
numpy库数组拼接np.concatenate 原文:https://blog.csdn.net/zyl1042635242/article/details/43162031 思路:numpy提供了 ...
- JSTL fn:replace()函数替换 换行符
转自:http://blog.163.com/chenjie_8392/blog/static/439339842010513128139/ 近日在使用textarea时,输入了回车,为了将texta ...
- YUV 和 YCbCr 辨析
YCbCr或Y'CbCr 是在世界数字组织视频标准研制过程中作为ITU-R BT1601 建议的一部分, 其实是YUV经过缩放和偏移的翻版. 通常会用于影片中的影像连续处理,或是数字摄影系统中. 其中 ...
- JS中字符串的编码 解码
DEPTNAME 是一个字符串 编码: DEPTNAME = encodeURI(encodeURI(DEPTNAME)); 解码: DEPTNAME = decodeURI(DEPTNAME,&qu ...
- BZOJ 4166: 月宫的符卡序列
如果使用回文树,节点 \(u\) 的回文串和 \(fail_u\) 的回文串中心不一样,因为回文树的 \(fail\) 指针指向的是最长回文后缀,没法快速解决异或和 考虑魔改回文树,用马拉车来解决,扩 ...
- keep-alive 用法 及activated,deactivated这两个生命周期函数
keep-aliveProps: include - 字符串或正则表达式.只有名称匹配的组件会被缓存.exclude - 字符串或正则表达式.任何名称匹配的组件都不会被缓存.max - 数字.最多可以 ...
- TCP 3次握手 && 4次分手
原文:https://github.com/jawil/blog/issues/14 3次握手 第一次握手:建立连接.客户端发送连接请求报文段,将SYN位置为1,Sequence Number为x:然 ...
- swoole之内存
一.代码 <?php // 可以用来数据共享 // 执行完后 自动释放 // 创建内存表 $table = new swoole_table(1024); // 内存表增加一列 $table-& ...
- Hadoop操作经验
系统日志文件写入到MySQL中,NoSQL中一般存储独立的关联性不大的非业务数据. 单个NameNode也可以恢复,从SecondaryNameNode恢复:两个NameNode是可以做负载均衡:更高 ...