Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- #define ll long long
- #define int long long
- const int inf = 1e9;
- ll M2 = 1e9 + 9, M1 = 1e9 + 7;
- //mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
- void solve() {
- int n;
- cin >> n;
- vector<int> a(n);
- for (auto &x : a) {
- cin >> x;
- }
- vector<int> dp(n, inf);
- dp[0] = 1;
- for (int i = 0; i < n; ++i) {
- if (i > 0) {
- dp[i] = min(dp[i], dp[i - 1] + 1);
- }
- if (i + a[i] < n) {
- dp[i + a[i]] = min(dp[i + a[i]], (i == 0 ? 0 : dp[i - 1]));
- }
- }
- cout << dp[n - 1] << '\n';
- }
- signed main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- ll thrush = 1;
- cin >> thrush;
- while (thrush--) { solve();}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement