D
如果可以的话点个赞和关注,谢谢大家对本题解的支持
#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll N=1e5+10; ll n, a[N], dp0[N], dp1[N]; void work(){ cin>>n; for(ll i=0;i<n;i++) scanf("%lld",&a[i]); dp1[0]=(a[0]==0), dp0[0]=(a[0]==1); for(ll i=1;i<n;i++){ dp0[i]=min(dp0[i-1]+(a[i]==1),dp1[i-1]+1); dp1[i]=min(dp1[i-1]+(a[i]==0),dp0[i-1]+1); } cout<<dp0[n-1]<<endl; return ; } int main(){ work(); return 0; }