Description
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
- on this day the gym is closed and the contest is not carried out;
- on this day the gym is closed and the contest is carried out;
- on this day the gym is open and the contest is not carried out;
- on this day the gym is open and the contest is carried out.
On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).
Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.
Input
The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of days of Vasya‘s vacations.
The second line contains the sequence of integers a1, a2, ..., an (0 ≤ ai ≤ 3) separated by space, where:
- ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out;
- ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out;
- ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out;
- ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out.
Output
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
- to do sport on any two consecutive days,
- to write the contest on any two consecutive days.
Sample Input
Input
41 3 2 0
Output
2
Input
71 3 3 2 1 2 3
Output
0
Input
22 2
Output
1
用k记录每天的状态,b[i]记录从第一天到第i天休息的天数,每一天的状态只与前一天有关,尽量保证能工作就不休息。
1 // 0 健身房关门 没比赛 2 // 1 健身房关门 有比赛 3 // 2 健身房开门 没比赛 4 // 3 健身房开门 有比赛 5 #include <cstdio> 6 int n,a[150],k,i,b[150]; 7 int main() 8 { 9 10 while(scanf("%d",&n)!=EOF) 11 { 12 b[0]=0; 13 k=0; 14 for(int i=1;i<=n;i++) 15 { 16 scanf("%d",&a[i]); 17 } 18 for(int i = 1 ; i <= n ; i++) 19 { 20 if(a[i] == 0) 21 { 22 b[i]=b[i-1]+1; 23 k=0; 24 } 25 else 26 { 27 if(a[i] == 3) 28 { 29 b[i]=b[i-1]; 30 k=3-k; 31 } 32 else 33 { 34 if(a[i] == k) 35 { 36 b[i]=b[i-1]+1; 37 k=0; 38 } 39 else 40 { 41 b[i]=b[i-1]; 42 k=a[i]; 43 } 44 } 45 } 46 } 47 printf("%d\n",b[n]); 48 } 49 }