class Solution {
public:
int jump(int A[], int n) {
int * step = new int[n];
step[0] = 0;
int pos = 1;
for (int i = 0; i < n; i++) {
int j;
for (j = pos; j <= A[i] + i && j < n; j++) {
step[j] = step[i] + 1;
}
pos = j;
}
int ans = step[n - 1];
delete []step;
return ans;
}
};