Codeforces Round #363 (Div. 2) C

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 ndays: 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:

  1. on this day the gym is closed and the contest is not carried out;
  2. on this day the gym is closed and the contest is carried out;
  3. on this day the gym is open and the contest is not carried out;
  4. 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.

Examples

input

41 3 2 0

output

2

input

71 3 3 2 1 2 3

output

0

input

22 2

output

1

Note

In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have 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 will not have a rest for a single day.

In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.

dp[i][j]第i天做第j个事情,可以休息几天~

#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;
}

  

时间: 2024-08-07 09:28:11

Codeforces Round #363 (Div. 2) C的相关文章

Codeforces Round #363 (Div. 2)

A. Launch of Collider 根据字符左移或右移,输出第一次碰撞的位置,不然输出-1 1 #include <cstdio> 2 #include <iostream> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 #define LL long long 7 char ch[200005]; 8 LL a[200005],ans; 9 int n; 1

CodeForces 698A - Vacations (Codeforces Round #363 (Div. 2))

要么去体育馆,要么去比赛,要么闲在家里 给出每一天体育馆和比赛的有无情况,要求连续两天不能去同一个地方 问最少闲几天 DP方程很容易看出 dp(第i天能去的地方) = min(dp(第i-1天的三种情况)) : dp(第i天呆在家里) = min(dp(第i-1天的三种情况))+1: 1 #include <cstdio> 2 #include <iostream> 3 using namespace std; 4 #define inf 0x3f3f3f3f 5 int a[10

Codeforces Round #363 Div.2[11110]

好久没做手生了,不然前四道都是能A的,当然,正常发挥也是菜. A:Launch of Collider 题意:20万个点排在一条直线上,其坐标均为偶数.从某一时刻开始向左或向右运动,速度为每秒1个单位长度.输入给出每个点的坐标及其移动的方向,求发生第一次碰撞的时间,若不会碰撞,则输出-1 最先发生碰撞的是一定是初始时相邻的两个点,因此只需对每个点循环一边,判断其是否会与下一个点碰撞,并求出其时间即可. #include<stdio.h> #include<stdlib.h> int

Codeforces Round #363 (Div. 1) C. LRU

题意: n个数,长度为k的缓存,每次询问,每个数以pi的概率被选,如果不在缓存区则加入,如果缓存区满了,则第一个进缓存的出来,问10^100次询问以后每个数在缓存的概率 思路: 状压DP,看了hzwer的代码 f[x]表示当前状态为x的概率 枚举不在缓存区的数:f[t]+=f[x]*(p[i]/tot);  t=x|(1<<(i-1)); tot是当前状态情况下,不在缓存区的所有概率 如果缓存区数大于k,则当前状态概率为0 1 // #pragma comment(linker, "

Codeforces Round #363 (Div. 2)A-D

699A 题意:在一根数轴上有n个东西以相同的速率1m/s在运动,给出他们的坐标以及运动方向,问最快发生的碰撞在什么时候 思路:遍历一遍坐标,看那两个相邻的可能相撞,更新ans #include<cstdio> int n,num[200100]; char s[200100]; int main() { scanf("%d",&n); scanf("%s",s+1); for(int i=1;i<=n;i++) scanf("%

Codeforces Round #363 (Div. 2) B 暴力

Description You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*"). You have one bomb. If you lay the bomb at the cell (x

Codeforces Round #363 (Div. 2) A 水

Description There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles l

Codeforces Round #363 (Div. 2) A-C

A. Launch of Collider 找最近的R和L之间的距离 #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <queue> #include <vector> #include <iomanip> #include <math.h> #include <map> u

Codeforces Round #363 (Div. 2) C dp或贪心 两种方法

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