Algorithm/jumping-wooden-trunk/main.cc
2024-06-09 14:40:50 +08:00

20 lines
390 B
C++

#include <iostream>
using namespace std;
const int MAXN = 105;
int dp[MAXN], obstacle[MAXN];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> obstacle[i];
dp[i] = n - 1;
}
dp[1] = 0;
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= i + obstacle[i] && j <= n; j++) {
dp[j] = min(dp[j], dp[i] + 1);
}
}
cout << dp[n] << endl;
}