题目来自leetcode.com
https://leetcode.com/problems/jump-game/description/
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.
Determine if you are able to reach the last index.
#建立数组
lenth = input("the length of array :")
lenth = int(lenth)
j = 0
arr = []
while j<lenth:
arr.append(int(input()))
j += 1
#迭代算法?一棵树?
def judge(a,arr,lenth):
if arr[a]+a+1>= lenth:
return 1
i = a+1
while i<=a+arr[a]:
if judge(i,arr,lenth) == 1:
return 1
i += 1
return 0
if judge(0,arr,lenth):
print("True")
else:
print("Flase")