Untitled
user_5668965
c_cpp
a year ago
1.3 kB
9
Indexable
#include<bits/stdc++.h> using namespace std; #define ll long long #define mod 1000000007 #define f first #define s second #define si(x) scanf("%d",&x) #define sl(x) scanf("%I64d",&x) #define CLR(x) memset(x,0,sizeof(x)) #define RESET(x,a) memset(x,a,sizeof(x)) #define pi pair<int,int> #define pb push_back #define mp make_pair #define debug(x) cerr<<">value ("<<#x<<") : "<<x<<endl; int dp[3][200]; int a[200]; int INF=10000; int main() { // ios_base::sync_with_stdio(false); // cin.tie(NULL); int t,n,m,i,j; si(n); for(i=0;i<n;i++) { si(a[i]); dp[0][i]=dp[1][i]=dp[2][i]=INF; } dp[0][i]=dp[1][i]=dp[2][i]=INF; dp[0][0]=0; for(i=0;i<n;i++) { dp[0][i+1] = min( min(dp[0][i],dp[1][i]) , dp[2][i] ); dp[0][i+1]++; if(a[i]==1) { dp[1][i+1] = min(dp[0][i], dp[2][i] ); } else if(a[i]==2) { dp[2][i+1] = min(dp[0][i], dp[1][i] ); } else if(a[i]==3) { dp[1][i+1] = min(dp[0][i], dp[2][i] ); dp[2][i+1] = min(dp[0][i], dp[1][i] ); } } i=n; int ans= min( min(dp[0][i],dp[1][i]) , dp[2][i] ); printf("%d\n",ans); return 0; }
Editor is loading...
Leave a Comment