17996 Daily Cool Run (dp)
时间限制: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)的更多相关文章
- 2018牛客网暑期ACM多校训练营(第二场) A - run - [DP]
题目链接:https://www.nowcoder.com/acm/contest/140/A 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 131072K,其他语言262144K ...
- uva12486 Space Elevator(数位dp)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud 题目链接:https://uva.onlinejudge.org/index.ph ...
- Linux之crontab
一 cron crond位于/etc/rc.d/init.d/crond 或 /etc/init.d 或 /etc/rc.d /rc5.d/S90crond,最总引用/var/lock/subsys ...
- Project Euler 76:Counting summations
题目链接 原题: It is possible to write five as a sum in exactly six different ways: 4 + 13 + 23 + 1 + 12 + ...
- Linux系统下使用crontab添加计划任务的方法
在服务器中添加定期执行的任务,在很多情况下是非常必要的.比如,每天清理一次/tmp目录下的文件;没几分钟检查某一守护进程是否正常等等.这样计划任务就显得尤为方便.下面将介绍如何在Linux系统中 ...
- Linux小知识点汇总
1.crontab (1)crontab每10秒执行一次 * * * * * /bin/date >>/tmp/date.txt * * * * * sleep 10; ...
- F, A, MS, QM, RF的OFFER和经历 -- Final update
昨天收到FB的电话,我的OFFER已经批下来了,这也意味着我的JOB HUNTING结束了,下 面是我这两个月来申请结果汇总: Applications (7): Facebook, Google, ...
- 算法入门经典大赛 Dynamic Programming
111 - History Grading LCS 103 - Stacking Boxes 最多能叠多少个box DAG最长路 10405 - Longest Common Subsequence ...
- Linux的cron和crontab
一 cron crond位于/etc/rc.d/init.d/crond 或 /etc/init.d 或 /etc/rc.d /rc5.d/S90crond,最总引用/var/lock/subsys/ ...
随机推荐
- 如何把一个excel工作薄中N个工作表复制到另一个工作薄中
一般遇到标题这样的情况,许多人可能会一个一个的复制粘贴,其实完全不必那么麻烦. 你可以按以下步骤来操作: 第一步:打开所有要操作的excel工作薄\n 第二步:按住Shift键,选择所有要复制的工作表 ...
- 使用charles 抓取手机上的操作
Charles上的设置要截取iPhone上的网络请求,我们首先需要将Charles的代理功能打开.在Charles的菜单栏上选择“Proxy”->“Proxy Settings”,填入代理端口8 ...
- iOS - iPhone开发 UILocalNotification的使用
OS下的Notification的使用 Notification 是智能手机应用编程中非常常用的一种传递信息的机制,而且可以非常好的节省资源,不用消耗资源来不停地检查信息状态(Pooling),在iO ...
- August 26th 2016 Week 35th Friday
It always seems impossible until it's done. 在事情未完成之前,一切都看似不可能. When I was young, once I had to lift ...
- chaper3_exerise_Uva1225_digit_counting
#include<iostream> #include<stdio.h> #include<cstring> using namespace std; ; int ...
- shared_ptr 和 unique_ptr
c++11标准废除乐auto_ptr, C++ 标准库智能指针 使用这些智能指针作为将指针封装为纯旧 C++ 对象 (POCO) 的首选项. unique_ptr 只允许基础指针的一个所有者. 除非你 ...
- Codeforces Round #324 (Div. 2) C (二分)
题目链接:http://codeforces.com/contest/734/problem/C 题意: 玩一个游戏,一开始升一级需要t秒时间,现在有a, b两种魔法,两种魔法分别有m1, m2种效果 ...
- selenium--python如何定位一组元素并返回文本值
from selenium import webdriverimport time a=[] #创建一个空列表用于存储查询到的元素组driver = webdriver.Firefox()driver ...
- Android Tab -- 使用ViewPager、PagerTitleStrip/PagerTabStrip来实现
原文地址:http://blog.csdn.net/crazy1235/article/details/42678877 效果:滑动切换:点击标签切换. 代码:https://github.com/l ...
- 验证码的种类与实现 C#封装类 - .NET MVC WEBFORM
验证码方式 1.随机字母或者数字,纯文本验证码 这种非常容易破解 ,市场上有大量的现成接口或者工具,背景越复杂难度越高. 2.题库验证码 要破解这种验证码,需要人工收集题库才可以破解,可以免疫不是专门 ...