dp로 뒤에서부터 최솟값을 가져와 0까지 역산했습니다.
for test in range(1, int(input()) + 1):
N, *battery = map(int, input().split())
dp = [float('inf')] * N
dp[N - 1] = 0
for i in range(N - 1, -1, -1):
for j in range(i - 1, -1, -1):
if j + battery[j] >= i:
dp[j] = min(dp[j], dp[i] + 1)
print(f'#{test} {dp[0] - 1}')
'practivceAlgorithm > swexpertacademy' 카테고리의 다른 글
[SWEA][Python] 5247 연산 (0) | 2021.10.06 |
---|---|
[SWEA][Python] 5209 최소 생산 비용 (0) | 2021.10.06 |
[SWEA][Python] 5205 퀵정렬 (0) | 2021.10.02 |
[SWEA][Python] 5204 병합정렬 (0) | 2021.10.02 |
[SWEA][Python] 1244 최대상금 (0) | 2021.10.01 |