Jump Game II
来源:互联网 发布:淘宝小类目让我发财了 编辑:程序博客网 时间:2024/06/11 17:01
Jump Game II
Given an array of non-negative integers, you are initially positioned at the first index of the array.
Each element in the array represents your maximum jump length at that position.
Your goal is to reach the last index in the minimum number of jumps.
For example:
Given array A = [2,3,1,1,4]
The minimum number of jumps to reach the last index is 2
. (Jump 1
step from index 0 to 1, then 3
steps to the last index.)
int* dp; int jump(int A[], int n) { if(n==0) { return INT_MAX; } dp = new int[n]; dp[0] = 0; for(int i=1;i<n;i++) { dp[i] = INT_MAX; } for(int i=1;i<n;i++) { for(int j=0;j<i;j++) { if(j+A[j]>=i) { int tmp = dp[j]+1; if(tmp < dp[i]) { dp[i] = tmp; break; } } } } return dp[n-1]; }
0 0
- Jump Game &Jump Game II
- Jump Game/Jump Game II
- LeetCode: Jump Game II
- LeetCode Jump Game II
- LeetCode: Jump Game II
- [Leetcode] Jump Game II
- [LeetCode] Jump Game II
- [Leetcode] Jump Game ii
- leetcode Jump Game II
- Jump Game II
- Jump Game II
- Jump Game II
- leetcode Jump Game II
- [LeetCode]Jump Game II
- Jump Game II
- Jump Game II
- Jump Game II
- Jump Game II
- 漢字簡化得不償失
- Linux多线程——使用信号量同步线程
- 【拓扑排序】 HDOJ 1811 Rank of Tetris
- 热门游戏 2048 C++ 源代码 再版 分享
- 如何创建和解压tar.xz文件
- Jump Game II
- netbeans for php项目常用快捷键说明
- 图像化矩阵Matlab程序
- 文件重命名之动态修改ListView里指定Item中的组件属性
- 07-0. 写出这个数 (20)
- cocos2dx 3.1.1 Lua相对于2.X的更新
- 行编辑程序实现
- Tomcat的启动方法
- centos6.5 防火墙关闭