11060번: 점프 점프

문제접근🤔


놓쳤던 부분😅


코드😁


2020 KB

0 ms

#include <iostream>
#include <algorithm>
using namespace std;

#define MAX 214748364

int main(void) {
	int n;
	int input;
	int dp[1001];

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	fill(dp, dp + 1001, MAX);

	cin >> n;
	dp[1] = 0;
	for (int i = 1; i <= n; i++) {
		cin >> input;
		for (int j = 1; j <= input; j++) {
			if (i + j > 1000)
				break ;
			dp[i + j] = min(dp[i + j], dp[i] + 1);
		}
	}
	if (dp[n] == MAX)
		cout << "-1";
	else
		cout << dp[n];
	return (0);
}