当前位置:网站首页>LeetCode 1696. Jumping game VI daily question
LeetCode 1696. Jumping game VI daily question
2022-07-07 16:58:00 【@Little safflower】
Problem description
I'll give you a subscript from 0 The starting array of integers nums And an integer k .
At first you were subscribing 0 It's about . Each step , You can jump forward at most k Step , But you can't jump out of the bounds of an array . in other words , You can start with the subscript i Jump to the [i + 1, min(n - 1, i + k)] contain Any position of the two endpoints .
Your goal is to get to the last position in the array ( Subscript to be n - 1 ), Yours score Is the sum of all the numbers passed .
Please return to what you can get Maximum score .
Example 1:
Input :nums = [1,-1,-2,4,-7,3], k = 2
Output :7
explain : You can choose subsequences [1,-1,4,3] ( The numbers in bold above ), And for 7 .
Example 2:Input :nums = [10,-5,-2,4,0,3], k = 3
Output :17
explain : You can choose subsequences [10,4,3] ( It's bold ), And for 17 .
Example 3:Input :nums = [1,-5,-20,4,-1,3,-6,-3], k = 2
Output :0
Tips :
1 <= nums.length, k <= 105
-104 <= nums[i] <= 104source : Power button (LeetCode)
link :https://leetcode.cn/problems/jump-game-vi
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
java
class Solution {
public int maxResult(int[] nums, int k) {
int n = nums.length;
int[] dp = new int[n];
Arrays.fill(dp,Integer.MIN_VALUE);
dp[0] = nums[0];
for(int i = 0;i < n;i++){
// jump k Time
for(int j = i + 1;j < n && j <= i + k;j++){
// Score after jump
int nextScore = dp[i] + nums[j];
// Update to a higher score after jumping
if(nextScore > dp[j]) dp[j] = nextScore;
// Filter
if(dp[j] >= dp[i]) break;
}
}
return dp[n - 1];
}
}
边栏推荐
- 谈谈 SAP 系统的权限管控和事务记录功能的实现
- Vs2019 configuration matrix library eigen
- LeetCode 1981. 最小化目标值与所选元素的差 每日一题
- 全网“追杀”钟薛高
- [C language] question set of X
- Imitate the choice of enterprise wechat conference room
- 在哪个期货公司开期货户最安全?
- Three. JS series (3): porting shaders in shadertoy
- 01tire+ chain forward star +dfs+ greedy exercise one
- Talk about the realization of authority control and transaction record function of SAP system
猜你喜欢

【MySql进阶】索引详解(一):索引数据页结构

skimage学习(3)——使灰度滤镜适应 RGB 图像、免疫组化染色分离颜色、过滤区域最大值

Prediction - Grey Prediction

QT中自定义控件的创建到封装到工具栏过程(一):自定义控件的创建

QT 图片背景色像素处理法
ByteDance Android gold, silver and four analysis, Android interview question app

如何选择合适的自动化测试工具?

Personal notes of graphics (4)
As an Android Developer programmer, Android advanced interview

面向接口编程
随机推荐
Record the migration process of a project
【DesignMode】外观模式 (facade patterns)
[medical segmentation] attention Unet
字节跳动高工面试,轻松入门flutter
The team of East China Normal University proposed the systematic molecular implementation of convolutional neural network with DNA regulation circuit
编程模式-表驱动编程
Opencv configuration 2019vs
LeetCode 1186. 删除一次得到子数组最大和 每日一题
Geoserver2.18 series (5): connect to SQLSERVER database
LocalStorage和SessionStorage
Binary search tree (features)
Three. JS series (1): API structure diagram-1
LeetCode 1986. 完成任务的最少工作时间段 每日一题
logback. XML configure logs of different levels and set color output
ATM system
Inner monologue of accidental promotion
正在准备面试,分享面经
Personal notes of graphics (3)
PHP realizes wechat applet face recognition and face brushing login function
值得一看,面试考点与面试技巧