当前位置:网站首页>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];
}
}
边栏推荐
- Opportunity interview experience summary
- Module VI
- Lowcode: four ways to help transportation companies enhance supply chain management
- 偶然升职的内心独白
- Read PG in data warehouse in one article_ stat
- HAVE FUN | “飞船计划”活动最新进展
- Geoserver2.18 series (5): connect to SQLSERVER database
- LeetCode 1654. 到家的最少跳跃次数 每日一题
- LeetCode 1155. 掷骰子的N种方法 每日一题
- LeetCode-SQL第一天
猜你喜欢

Skimage learning (3) -- gamma and log contrast adjustment, histogram equalization, coloring gray images

Binary search tree (basic operation)

Record the migration process of a project

Three. JS series (2): API structure diagram-2

Lowcode: four ways to help transportation companies enhance supply chain management

"The" "PIP" "entry cannot be recognized as the name of a cmdlet, function, script file, or runnable program."

HAVE FUN | “飞船计划”活动最新进展
![[medical segmentation] attention Unet](/img/f4/cf5b8fe543a19a5554897a09b26e68.png)
[medical segmentation] attention Unet

全网“追杀”钟薛高
作为Android开发程序员,android高级面试
随机推荐
three. JS create cool snow effect
Master this promotion path and share interview materials
直接上干货,100%好评
编程模式-表驱动编程
Lowcode: four ways to help transportation companies enhance supply chain management
Geoserver2.18 series (5): connect to SQLSERVER database
QT视频传输
URL和URI的关系
C语言进阶——函数指针
深度监听 数组深度监听 watch
skimage学习(2)——RGB转灰度、RGB 转 HSV、直方图匹配
LeetCode 1043. 分隔数组以得到最大和 每日一题
23. 合并K个升序链表-c语言
The latest interview experience of Android manufacturers in 2022, Android view+handler+binder
Module VI
Direct dry goods, 100% praise
第九届 蓝桥杯 决赛 交换次数
time标准库
[designmode] facade patterns
Opencv configuration 2019vs