当前位置:网站首页>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];
}
}
边栏推荐
- 掌握这个提升路径,面试资料分享
- Interface oriented programming
- Introduction to ThinkPHP URL routing
- Horizontal and vertical centering method and compatibility
- 【PHP】PHP接口继承及接口多继承原理与实现方法
- Record the migration process of a project
- 【Seaborn】组合图表、多子图的实现
- DAPP defi NFT LP single and dual currency liquidity mining system development details and source code
- 整理几个重要的Android知识,高级Android开发面试题
- LeetCode 1626. 无矛盾的最佳球队 每日一题
猜你喜欢
字节跳动Android金三银四解析,android面试题app
Talk about the realization of authority control and transaction record function of SAP system
The difference and working principle between compiler and interpreter
Have fun | latest progress of "spacecraft program" activities
最新Android面试合集,android视频提取音频
Direct dry goods, 100% praise
Pycharm IDE下载
Sort out several important Android knowledge and advanced Android development interview questions
低代码(lowcode)帮助运输公司增强供应链管理的4种方式
Pycharm terminal enables virtual environment
随机推荐
skimage学习(3)——使灰度滤镜适应 RGB 图像、免疫组化染色分离颜色、过滤区域最大值
LeetCode 1186. 删除一次得到子数组最大和 每日一题
null == undefined
Set the route and optimize the URL in thinkphp3.2.3
最新Android面试合集,android视频提取音频
Interface oriented programming
第九届 蓝桥杯 决赛 交换次数
二叉搜索树(基操篇)
AutoLISP series (1): function function 1
LeetCode-SQL第一天
01tire+ chain forward star +dfs+ greedy exercise one
Opencv configuration 2019vs
ATM系统
Advanced C language -- function pointer
Personal notes of graphics (1)
typescript ts基础知识之tsconfig.json配置选项
LeetCode 1477. 找两个和为目标值且不重叠的子数组 每日一题
浅浅理解.net core的路由
QT视频传输
1亿单身男女“在线相亲”,撑起130亿IPO