Jumping game
Given a non-negative integer array, assume that your initial position is the first subscript of the array.
Each element in the array represents the maximum length that you can jump in that position.
Make sure you are able to jump to the last subscript of the array.
For example:
A = [2,3,1,1,4],
return true.
A = [3,2,1,0,4],
return FALSE.
Format:
The first line enters a positive integer n, the next line, and the input array a[n]. If you can skip to the last subscript, output "true", otherwise output "false"
Sample input
52 0 2) 0 1
Sample output
True
1#include"iostream"2 #defineMAX 100003 using namespacestd;4 5 intJumpintNint*a,intp)6 {7 if(P >=N)8 return 1;9 for(inti = a[p]; I>0; i--)Ten { One if(Jump (n, a, p + i) = =1) A return 1; - Else -A[p + i] =-1;//p+1 position is not the last . the } - return 0; - } - + intMain () - { + intA[max]; A intN,tag; atTag =0; -CIN >>N; - for(inti =0; i<n; i++) - { -CIN >>A[i]; - } in - if(Jump (N,a,0)) tocout <<"true"; + Else -cout <<"false"; the *}
Garlic Guest Jumping Game