题解
仍然是见微知著,假设已知当前数组及其所有子数组的最小删除个数,这时往数组的前面添加一个元素,则这个数要么被删掉,要么作为领头
code
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int a[200005];
int dp[200005];
void solve()
{
int n;
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
dp[n+1]=0;
for(int i=n;i>=1;i--)
{
dp[i]=dp[i+1]+1;
if(i+a[i]<=n) dp[i]=min(dp[i],dp[i+a[i]+1]);
}
cout<<dp[1]<<'\n';
}
int main()
{
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t=1;
cin>>t;
while(t--) solve();
return 0;
}
标签:200005,Sequence,int,long,Block,数组,dp
From: https://www.cnblogs.com/pure4knowledge/p/18302892