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. ZOJ 649 Rescue(优先队列+bfs)

    Rescue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

  2. LINUX修改IP地址

    以前都是使用自动IP动态分配获取IP的,虽然每次获得的ip都是相同的,但我还是决定自己设置一个IP.输入命令:[root@localhost ~]# ifconfig eth0 219.246.177 ...

  3. js第一天 inner html value

    <html> <head> <meta charset="utf-8" /> <title></title> <s ...

  4. Codeforce#354_B_Pyramid of Glasses(模拟)

    题目连接:http://codeforces.com/contest/676/problem/B 题意:给你一个N层的杯子堆成的金字塔,倒k个杯子的酒,问倒完后有多少个杯子的酒是满的 题解:由于数据不 ...

  5. allocator 类

    allcator是一个模板类 定义在memory头文件中,将内存分配与对象构造分开,分配的内存是原始的.未构造的 一.how to use 因其实一个类,则使用allcator时需要首先声明一个类对象 ...

  6. 面向方面编程(AOP)

    简介 如果你很熟悉面向方面编程(AOP),你就会知道给代码增加"切面"可以使代码更清晰并且具有可维护性.但是AOP通常都依赖于第三方类库或者硬编码的.net特性来工作.虽然这些实现 ...

  7. linux 架设 postfix 邮件服务器

    http://www.cnblogs.com/dudu/archive/2012/12/12/linux-postfix-mailserver.html

  8. swap in java?

    Is it possible to write a swap method in java? these two variables will be primitives. It's not poss ...

  9. 使用onclick跳转到其他页面。使用button跳转到指定url

    1. onclick="javascript:window.location.href='aa.htm'" 2.  onclick="location='URL'&quo ...

  10. 利用npoi把多个DataTable导入Excel多个sheet中

    { 题外拓展:把datatable插入dataset DataTable fuben = new DataTable();//定义的datatablefuben = table.Tables[0].C ...