第一题帮朋友做的,AC了
LUCKY BOY<zhang.yun.hao@foxmail.com> 16:26:24
#include<iostream>
#include<vector>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> vec;
	vector<int> dp(n + 1, -1);
	for (int i = 0; i < n; i++) {
		int tmp;
		cin >> tmp;
		vec.push_back(tmp);
	}
	dp[0] = 0;
	for (int i = 1; i <= n; i++) {
		int min = 99999;
                //从i节点之前找到可以跳到i的一个节点,该节点必须可到达,即不为-1
		for (int j = 0; j < i; j++) {
			if (vec[j] >= i - j) {
				if (min > dp[j] && dp[j] != -1)
					min = dp[j];
			}
		}
		dp[i] = (min == 99999 ? -1 : min + 1);
	}
	cout << dp[n] << endl;
}