时间限制:1000MS  内存限制:65535K
提交次数:0 通过次数:0

题型: 编程题   语言: 不限定

Description

Daily Cool Run is a popular game, and Xdp enjoys playing the game recently.
While playing the game, you may get normal coins or flying coins by running and jumping.
Now, he meets a problem that what is the maximum score he can obtain.
To simplify the problem, we suppose that the maps of the game are 2 * n retangles, whose second rows are the ground.
At the beginning of the game, the player will start from the grid (2, 1) (the lower left corner of a map).
During the game, you have two choices, Run or Jump. When you are on the ground of grid (2, i),
1. Run to grid (2, i + 1);
2. Jump to grid (2, i + 3) by go through grids (1, i + 1) and (1, i + 2).
Know that you can’t land while jumping , and must follow the path stated above .When you arrive one of the last two grids, the game will be over.
Now, Xdp knows the maps of the game, whose grids are assigned to a value x(0 <= x <= 100).
If x=0, it means this grid is empty, else it means there is a coin whose value is x.
Now, can you tell me what is the maximum score you can get?

输入格式

There are at most 100 cases.
The first line is an integer T, the number of the cases.
In each case, the first line is a integer n (n <= 10

5

).
The Following two lines this a 2 * n rectangular, that means in each line,
there are n integers (x1, x2, …. xn). ( 0 <= x < =100, 0 means that this gird is an empty gird,
others represent the coins, x is its value).

输出格式

For each test case, output a single line with an integer indicates the maximum score .

输入样例

2

8
0 0 1 1 0 1 1 0
2 1 0 0 1 0 0 1 5
0 0 1 1 0
2 1 2 0 1

输出样例

9
6
思路:dp[i]表示在二维矩阵中走到第二行的第i列时所获得的最大值
dp[i] = max(dp[i - 1] + a[i], dp[i - 3] + a[i - 2] + a[i - 1] + b[i]) , i > 3 ;
dp[i] = dp[i - 1] + a[i] , i <= 3
由于在最后会从 a[n] 或 b[n]处结束, 为避免处理的麻烦,干脆延长地图,并使延长部分的价值为0, 这样就相当于最终一定会落在地上
 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <iostream>
#include <cmath>
using namespace std ;
int a[], b[] ;
int dp[] ;
int main()
{
int t ;
scanf("%d",&t) ;
while(t--)
{
int n ;
scanf("%d",&n) ;
for(int i = ; i <= n ;++i) scanf("%d",&a[i]) ;
for(int i = ; i <= n ;++i) scanf("%d",&b[i]) ;
a[n + ] = a[n + ] = a[n + ] = b[n + ] = b[n + ] = b[n + ] = ;
memset(dp, , sizeof dp) ;
for(int i = ; i <= n + ; ++i)//延长地图长度为n + 3
if(i > ) dp[i] = max(b[i] + a[i - ] + a[i - ] + dp[i - ], b[i] + dp[i - ]) ;
else dp[i] = b[i] + dp[i - ] ;
printf("%d\n",dp[n + ]) ;
}
}

17996 Daily Cool Run (dp)的更多相关文章

  1. 2018牛客网暑期ACM多校训练营(第二场) A - run - [DP]

    题目链接:https://www.nowcoder.com/acm/contest/140/A 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 131072K,其他语言262144K ...

  2. uva12486 Space Elevator(数位dp)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 题目链接:https://uva.onlinejudge.org/index.ph ...

  3. Linux之crontab

    一  cron crond位于/etc/rc.d/init.d/crond 或 /etc/init.d 或 /etc/rc.d /rc5.d/S90crond,最总引用/var/lock/subsys ...

  4. Project Euler 76:Counting summations

    题目链接 原题: It is possible to write five as a sum in exactly six different ways: 4 + 13 + 23 + 1 + 12 + ...

  5. Linux系统下使用crontab添加计划任务的方法

     在服务器中添加定期执行的任务,在很多情况下是非常必要的.比如,每天清理一次/tmp目录下的文件;没几分钟检查某一守护进程是否正常等等.这样计划任务就显得尤为方便.下面将介绍如何在Linux系统中 ...

  6. Linux小知识点汇总

        1.crontab    (1)crontab每10秒执行一次  * * * * * /bin/date >>/tmp/date.txt  * * * * * sleep 10; ...

  7. F, A, MS, QM, RF的OFFER和经历 -- Final update

    昨天收到FB的电话,我的OFFER已经批下来了,这也意味着我的JOB HUNTING结束了,下 面是我这两个月来申请结果汇总: Applications (7): Facebook, Google, ...

  8. 算法入门经典大赛 Dynamic Programming

    111 - History Grading LCS 103 - Stacking Boxes 最多能叠多少个box DAG最长路 10405 - Longest Common Subsequence ...

  9. Linux的cron和crontab

    一 cron crond位于/etc/rc.d/init.d/crond 或 /etc/init.d 或 /etc/rc.d /rc5.d/S90crond,最总引用/var/lock/subsys/ ...

随机推荐

  1. php date函数 参数详细

    time()在PHP中是得到一个数字,这个数字表示从1970-01-01到现在共走了多少秒,很奇怪吧 不过这样方便计算, 要找出前一天的时间就是 time()-60*60*24; 要找出前一年的时间就 ...

  2. iOS MD5加密

    1.MD5加密 Message Digest Algorithm MD5(中文名为消息摘要算法第五版)为计算机安全领域广泛使用的一种散列函数,用以提供消息的完整性保护.该算法的文件号为RFC 1321 ...

  3. September 7th 2016 Week 37th Wednesday

    Patience is bitter, but its fruit is sweet. 忍耐是痛苦的,但它的果实却是甜蜜的. However, many may give up before they ...

  4. Java 配色方案--Dark Flash Builder - by Wilson Silva

    http://eclipsecolorthemes.org/?view=theme&id=1855

  5. Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)(set容器里count函数以及加强for循环)

    题目链接:http://codeforces.com/contest/722/problem/D 1 #include <bits/stdc++.h> #include <iostr ...

  6. DB2应用中嵌入式SQL取值入本地变量

    Declare section for host variables in C and C++ embedded SQL applications You must use an SQL declar ...

  7. 关于ActionContext.getContext()的用法心得

    转: 为了避免与Servlet API耦合在一起,方便Action类做单元测试,Struts 2对HttpServletRequest.HttpSession和ServletContext进行了封装, ...

  8. self和parent的用法

    总结 self  , parent 的用法               只能用在类的内部 self  本类  (不要理解成本对象) parent 父类 在引入自身的静态属性/静态方法 以及父类的方法时 ...

  9. JQuery阻止冒泡事件on绑定中异常情况分析

    科普下事件冒泡以及默认行为,以下面例子举列子:     事件冒泡:当点击内部button元素时,会触发自身及外层 a的点击事件,这就是事件冒泡引起的.事件会随着 DOM 的层次结构依次向上传播. 事件 ...

  10. SpringBoot Jms

    https://dzone.com/articles/spring-boot-example-of-spring-integration-and-acti