Untitled
unknown
python
a year ago
410 B
9
Indexable
def solve():
n = int(input())
a = [int(x) for x in input().split()]
dp = [n + 1] * n
def get(pos):
if pos > n:
return n + 1
if pos == n:
return 0
return dp[pos]
dp[-1] = 1
for i in range(n - 2, -1, -1):
dp[i] = min(dp[i + 1] + 1, get(i + a[i] + 1))
print(dp[0])
for _ in range(int(input())):
solve()Editor is loading...
Leave a Comment