Vacations

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:

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

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;

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <ext/rope>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define vi vector<int>
#define pii pair<int,int>
#define mod 1000000007
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
const int maxn=1e2+;
const int dis[][]={{,},{-,},{,-},{,}};
using namespace std;
using namespace __gnu_cxx;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m,a[maxn],dp[][maxn];//0,休息;1,考试;2,运动;
int main()
{
int i,j,k,t;
scanf("%d",&n);
rep(i,,n)scanf("%d",&a[i]);
memset(dp,inf,sizeof(dp));
for(i=n;i>=;i--)
{
if(i==n)
{
dp[][i]=;
if(a[i]==||a[i]==)dp[][i]=;
if(a[i]==||a[i]==)dp[][i]=;
}
else
{
dp[][i]=min({dp[][i+],dp[][i+],dp[][i+]})+;
if(a[i]==||a[i]==)
dp[][i]=min(dp[][i+],dp[][i+]);
if(a[i]==||a[i]==)
dp[][i]=min(dp[][i+],dp[][i+]);
}
}
printf("%d\n",min({dp[][],dp[][],dp[][]}));
//system ("pause");
return ;
}

Vacations的更多相关文章

  1. CodeForces #363 div2 Vacations DP

    题目链接:C. Vacations 题意:现在有n天的假期,对于第i天有四种情况: 0  gym没开,contest没开 1  gym没开,contest开了 2 gym开了,contest没开 3 ...

  2. Codeforces Round #363 (Div. 2)->C. Vacations

    C. Vacations time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  3. Codeforces Round #363 (Div. 2) C. Vacations(DP)

    C. Vacations time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  4. Code Forces 698A Vacations

    题目描述 Vasya has nn days of vacations! So he decided to improve his IT skills and do sport. Vasya know ...

  5. CodeForces 699C - Vacations

    题目链接:http://codeforces.com/problemset/problem/699/C C. Vacations time limit per test1 second memory ...

  6. (贪心) Vacations 求休息的最少天数

    Description Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasy ...

  7. 【CodeForces 698A】Vacations

    f[i][0..2]表示第i天休息|运动|比赛最少的休息天数. #include <cstdio> #include <cstring> #include <algori ...

  8. CodeForces 698A Vacations

    题目链接 : http://codeforces.com/problemset/problem/698/A 题目大意: 阿Q有n天假期,假期中有三种安排 休息.健身.比赛.每天有三种选择条件: 0 健 ...

  9. 【动态规划】Codeforces 698A & 699C Vacations

    题目链接: http://codeforces.com/problemset/problem/698/A http://codeforces.com/problemset/problem/699/C ...

随机推荐

  1. RecyclerView onTouch & onClick 触摸事件与点击事件

    遇到一种情况需要处理,RecyclerView所在Activity需要处理滑动事件用于返回(onBackPressed). 手势检测: @Override public boolean onFling ...

  2. Screen tearing

    Umm, screen tearing happens when the frame rate and the monitor refresh rate don't match.  When that ...

  3. OLEDB和ODBC的区别

    ODBC(开放数据库互连):是Microsoft引进的一种早期数据库接口技术.它实际上是ADO的前身.早期的数据库连接是非常困难的. 每个数据库的格式都不一样,开发者得对他们所开发的每种数据库的底层A ...

  4. malloc without free, what happens?

    It's per-process. Once your process exits, the allocated memory is returned to the OS for use by oth ...

  5. 在CentOS 7下ISCSI和多路径部署文档【转】

    部署环境 设备:MD3860i, R630, S4820T(生产网络), N2024(管理网络) 操作系统:Centos 7 默认管理口的地址:A控192.168.129.101, B 控192.16 ...

  6. login/logout切换

    1. 前端按钮 <img border="0" width="18" height="18" src="<%=base ...

  7. 依赖注入(DI)和控制反转(IOC)【回顾】

    在java开发中广泛的使用了IOC的思想,在PHP中同样也在广泛使用. interface Coder { public function coding(); } 实现类Javaer class Ja ...

  8. 文件描述符和exec() close_on_exec

    #include <fcntl.h> #include <iostream> #include <unistd.h> using namespace std; in ...

  9. redis采用序列化方案存对象

    前几天被问到这样一个问题,redis怎么存对象,平时也没怎么注意,只知道redis存字符之类的,不过就是根据键存取值,不过对象的话还是不同的 首先来了解一下为什么要实现序列化 为什么要实现序列化接口 ...

  10. Cookie 的设置和获取

    获取:var userName = getCookieValue("userName"); 设置:setCookie("userName",equpid,24, ...