当前位置:网站首页>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];
}
}
边栏推荐
- 如何选择合适的自动化测试工具?
- LeetCode 1626. 无矛盾的最佳球队 每日一题
- The latest interview experience of Android manufacturers in 2022, Android view+handler+binder
- Personal notes of graphics (2)
- 【医学分割】attention-unet
- Module VI
- AutoLISP series (2): function function 2
- Record the migration process of a project
- Pisa-Proxy SQL 解析之 Lex & Yacc
- 面试题 01.02. 判定是否互为字符重排-辅助数组算法
猜你喜欢
[vulnhub range] thales:1
Cesium(3):ThirdParty/zip. js
DNS 系列(一):为什么更新了 DNS 记录不生效?
如何快速检查钢网开口面积比是否符合 IPC7525
Imitate the choice of enterprise wechat conference room
As an Android Developer programmer, Android advanced interview
The difference and working principle between compiler and interpreter
字节跳动Android面试,知识点总结+面试题解析
水平垂直居中 方法 和兼容
The latest interview experience of Android manufacturers in 2022, Android view+handler+binder
随机推荐
最新Android面试合集,android视频提取音频
【DesignMode】享元模式(Flyweight Pattern)
Laravel5.1 Routing - routing packets
【DesignMode】外观模式 (facade patterns)
ATM system
Opencv configuration 2019vs
LeetCode 1696. 跳跃游戏 VI 每日一题
【PHP】PHP接口继承及接口多继承原理与实现方法
Tidb cannot start after modifying the configuration file
全网“追杀”钟薛高
null == undefined
[Android -- data storage] use SQLite to store data
最新Android高级面试题汇总,Android面试题及答案
最新高频Android面试题目分享,带你一起探究Android事件分发机制
水平垂直居中 方法 和兼容
Find tags in prefab in unity editing mode
Personal notes of graphics (4)
Sqlserver2014+: create indexes while creating tables
dapp丨defi丨nft丨lp单双币流动性挖矿系统开发详细说明及源码
C语言进阶——函数指针