Description
Vasya have n days of vacations! So he decided-improve his IT skills and do sport. Vasya knows the following information about each of this ndays:whether that gym opened and whether a contest Was carried out in the Internet on that day. For the i-th day there is four options:
- The gym is closed and the contest are not carried out;
- The gym is closed and the contest are carried out;
- The gym is open and the contest are not carried out;
- The gym is open and the contest are carried out.
On any of the days Vasya can either has a rest or write the contest (if it is carried off on this day), or do sport (if the Gym is open on this day).
Find the minimum number of days on which Vasya would have a rest (it means, he'll not does sport and write the contest at T He same time). The only limitation this Vasya has- he does not want to does the same activity on the consecutive days:it means, he wi ll not does sport on both consecutive days, and write the contest on both consecutive days.
Input
The first line contains a positive integer n (1≤ n ≤100)-the number of days of Vasya ' s Vacat ions.
The second line contains the sequence of Integers a 1, a 2, ..., a n (0≤ a i ≤ 3) separated by space, where:
- a i equals 0, if on the I-th day of vacations the gym are closed and the contest is not carried out ;
- a i equals 1, if on the I-th day of vacations the gym was closed, but the contest is carried O UT;
- a i equals 2, if on the I-th day of vacations the gym are open and the contest is not carried Out;
- a i equals 3, if on the I-th day of vacations the gym are open and the contest is carried out .
Output
Print the minimum possible number of days on which Vasya would have a rest. Remember that Vasya refuses:
- To does sport on any of consecutive days,
- To write the contest in any of the consecutive days.
Examples
input
4
1 3 2 0
Output
2
input
7
1 3 3 2 1 2 3
Output
0
input
2
2 2
Output
1
Note
The first Test Vasya can write the contest on the day number 1 and does sport on the day number 3. Thus, he'll has a rest for only 2 days.
In the second Test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he is not having a rest for a.
In the third Test Vasya can does sport either on a day number 1 or number 2. He can does sport in both days, because it'll be contrary to the limitation. Thus, he'll has a rest for only one day.
DP[I][J] The first day to do the first J things, can rest a few days ~
#include <bits/stdc++.h>using namespace Std;int dp[1000][3];int inf= (1<<31) -1;int main () {int n; int num[19999]; cin>>n; for (int i=1;i<=n;i++) {cin>>num[i]; for (int j=0;j<=3;j++) {dp[i][j]=inf; }} for (int i=1;i<=n;i++) {if (num[i]==0) {dp[i][0]=min (Dp[i-1][0],min (DP[I-1][1],DP [I-1] [2])) +1; } if (num[i]==1) {dp[i][0]=min (Dp[i-1][0],min (dp[i-1][1],dp[i-1][2])) +1; Dp[i][1]=min (dp[i-1][0],dp[i-1][2]); } if (num[i]==2) {dp[i][0]=min (Dp[i-1][0],min (dp[i-1][1],dp[i-1][2])) +1; Dp[i][2]=min (dp[i-1][0],dp[i-1][1]); } if (num[i]==3) {dp[i][0]=min (Dp[i-1][0],min (dp[i-1][1],dp[i-1][2])) +1; Dp[i][2]=min (dp[i-1][0],dp[i-1][1]); Dp[i][1]=min (dp[i-1][0],dp[i-1][2]); }} int min=inf; for (int i=0;i<=3;i++) {min=min (Dp[n][i],min); } cout<<min<<endl; return 0;}
Codeforces Round #363 (Div. 2) C