时间限制: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. log4j介绍以及使用教程

    一.介绍 Log4j是Apache的一个开放源代码项目,通过使用Log4j,我们可以控制日志信息输送的目的地是控制台.文件.GUI组件.甚至是套接 口服务 器.NT的事件记录器.UNIX Syslog ...

  2. ios 横竖屏通知

    屏幕切换时,会发送一个通知.只要注册一个通知: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(do ...

  3. iptables配置(/etc/sysconfig/iptables)

    iptables -A INPUT -p tcp --dport 22 -j ACCEPTiptables -A INPUT -p tcp --dport 22 -j ACCEPTiptables - ...

  4. 你知道吗?Web的26项基本概念和技术

    这是我在网上看到一篇不错的文章,拿出来与大家分享一下:希望有所帮助 作者: 小鱼  来源: 前端里  发布时间: 2014-08-01 22:56  阅读: 10477 次  推荐: 51   原文链 ...

  5. 苹果应用 Windows 申请 普通证书 和Push 证书 Hbuilder 个推(2)

    s上一篇 讲述了android 如何打包,这一篇 看一下如何IOS下打包 在苹果上申请证书,及其麻烦,我写下来,有需要的直接拿走即可: 首先 苹果的证书分两种 一种是 development 证书,另 ...

  6. viewpager中彻底性动态添加、删除Fragment

    为了解决彻底删除fragment,我们要做的是:1.将FragmentPagerAdapter 替换成FragmentStatePagerAdapter,因为前者只要加载过,fragment中的视图就 ...

  7. Swift - 文件目录路径获取及数据储存(Home目录,文档目录,缓存目录)

    iOS应用程序只能在自己的目录下进行文件的操作,不可以访问其他的存储空间,此区域被称为沙盒.   应用沙盒结构分析 1.应用程序包:包含了所有的资源文件和可执行文件 2.Documents:保存应用运 ...

  8. AngularJS模型 ng-model 指令

    ng-model 指令用于绑定应用程序数据到 HTML 控制器(input, select, textarea)的值. ng-model 指令可以将输入域的值与 AngularJS 创建的变量绑定.例 ...

  9. mysql入门语句10条

    1,连接数据库服务器 mysql  -h host   -u root   -p  xxx(密码) 2,查看所有库 show databases; 3,选库 use 库名 4,查看库下面的表 show ...

  10. Scrapy爬取美女图片 (原创)

    有半个月没有更新了,最近确实有点忙.先是华为的比赛,接着实验室又有项目,然后又学习了一些新的知识,所以没有更新文章.为了表达我的歉意,我给大家来一波福利... 今天咱们说的是爬虫框架.之前我使用pyt ...