题干:

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.

题目大意:

Vasya在n天中,有三件事情可以做,健身、写作或者休息,但是健身和写作不能连续两天都去做,但是连续休息两天是允许的,问题是在这n天中,Vasya最少可以休息几天?

题意2::Vasyayo有n天的假期,他每天可以选择运动,比赛或者休息。但每天都四个状态,体育场开门没有比赛,体育场关门有比赛,体育场开门有比赛,体育场关门没比赛。问他最少休息多少天?

解题报告:

因为题目中显然有状态的转移,所以考虑dp

AC代码:

#include<bits/stdc++.h>using namespace std;
const int INF = 0x3f3f3f3f;
int dp[1000][4];//1是休息,2是比赛,3是健身   第二位代表当天做了什么(所以首先得能选择做这个决策,所以m=1时不需要更新 健身那一层),而不是
int a[1000];
int min(int x,int y,int z) {return min(x,min(y,z));
}
int main()
{int n;int minn ;cin>>n;for(int i = 1; i<=n; i++) {cin>>a[i];//1是比赛,2是健身 }//看我当天能够做什么事来选择更新什么值 for(int i = 1; i<=n; i++) {if(a[i] == 0) {minn = INF;for(int k = 1; k<=3; k++) minn = min(minn,dp[i-1][k]);
//          printf("minn = %d\n",minn);dp[i][1] = minn+1;dp[i][2] = dp[i][3] = INF;}else if(a[i] == 1) {dp[i][2] = min(dp[i-1][1],dp[i-1][3]);dp[i][1] = min(dp[i-1][1] + 1,dp[i-1][2]+1,dp[i-1][3] + 1);dp[i][3] = INF;}else if(a[i] == 2) {dp[i][1] = min(dp[i-1][1]+1,dp[i-1][2]+1,dp[i-1][3]+1);dp[i][2] = INF;dp[i][3] = min(dp[i-1][2],dp[i-1][1]);}else {dp[i][1] = min(dp[i-1][1]+1,dp[i-1][2]+1,dp[i-1][3]+1);dp[i][2] = min(dp[i-1][1],dp[i-1][3]);dp[i][3] = min(dp[i-1][1],dp[i-1][2]);}}
//  for(int i = 1; i<=n; i++)printf("%d\n",min(dp[n][1],dp[n][2],dp[n][3]));return 0 ;} 

【CF - 699C】 Vacations (日程安排 dp)相关推荐

  1. 第十五届全国大学生智能车安徽赛区参赛须知和竞赛日程安排

    安徽赛区参赛须知 和竞赛日程安排 各参赛队伍: 2020年第15届全国大学生智能汽车竞赛安徽赛区竞赛定于2020年11月7日-11月8日在合肥职业技术学院汇心湖校区举行. 联系人:吕菲 Email:l ...

  2. 预告 | AIS (ACL, IJCAI, SIGIR) 2019 论文报告会日程安排

    AlS2019是由中国中文信息学会青工委.杭州钱塘新区管委会.搜狗搜索联合举办的论文报告会. 会议将于2019年5月25日一5月26日,在杭州钱塘新区大创小镇国际创博中心内举办. 本次会议把ACL(国 ...

  3. 如何在outlook的日历Calendar里实现按照多时区显示日程安排

    如果您在一家跨国企业工作,免不了和本国以外的其他区域的程序员打交道,在进行会议安排时需要综合考虑所有与会者时区. 微软的outlook里的日历显示- calendar display贴心的提供了多时区 ...

  4. 2007.2.14 日程安排

    公元二零零七年二月十四日,农历腊月二十七,该天尤为特别,乃春节长假之初始.此外,该天将是片地鸳侣,漫天桃花之好时日,于是吾将广纳四方真气,闭关修炼,与世无争.        00:00 --7:10 ...

  5. 飞秋教程:日程安排记事提醒

    点击主面板上面的"日程安排记事提醒"按钮进入 新建日程记事 双击日程中的某天,对此日程进行记事安排. 也可以对进行批量增加,如指定每月.农历每年的生日等. 查看全部提醒和记事 对日 ...

  6. FullCalendar 一: 日程安排FullCalendar

    FullCalendar是一款基于jQuery的日历插件,适用于各种日程安排.工作计划等场景,您可以很方便的查看查看待办事项,标记重要事项以及绑定点击和拖动事件,能快速的整合到您的项目中,本文将简单介 ...

  7. ieda中快捷搜索_快捷指令(07)早上好(三)播报当日日程安排。

    机型:iPhone XR 系统:iOS13.2.3 快捷指令最新版 今天开始着手制作知友们留言最多的"早上好",今天先学习第三部分:播报当日日程安排. 首先我们来播放一下查看下效果 ...

  8. 在一个软件开发项目中进行实际日程安排的十二点提示(转)

    Laura Rose , QE Manager, Rational<?XML:NAMESPACE PREFIX = O /> <?XML:NAMESPACE PREFIX = ST1 ...

  9. 使用日程安排自动化测试来更好地管理时间与资源

    简介:在一个自动化测试系统中按日程安排一项测试是实现在特定的日期和时间内执行任务的重要组成部分.它不但能够帮助您更有效地使用测试资源,而且能够帮助您监视测试结果.本文介绍了关于这方面一些应当考虑的事项 ...

最新文章

  1. 手机端登陆github产生ssl handshake aborted error如何解决?
  2. golang 写入文件 覆盖旧文件 将旧文件清空
  3. TinyXML2 的使用
  4. ES-PHP向ES批量添加文档报No alive nodes found in your cluster
  5. android ViewPager 实现点击小圆点切换页面 案例
  6. CVPR 2021 | 天津大学提出PISE:形状与纹理解耦的人体图像生成与编辑方法
  7. Qt把已有工程添加到其他工程中作为子工程或新创建子工程
  8. django 按钮的样式_【实战演练】Python+Django网站开发系列11-成绩查询与成绩录入...
  9. android mvvm 官方例子,详解Android的MVVM框架 - 数据绑定
  10. Docker制作dotnet core控制台程序镜像
  11. LeetCode题——最长无重复子串
  12. 致谢!华为全联接2020精彩回顾
  13. 万维网之父:Facebook、Google 等硅谷巨头必须被拆分!
  14. Eclipse 快捷键整理
  15. log4j容器初始化探究
  16. mysql中varbinary什么意思_sql中varbinary 是什么数据类型
  17. 图像分割(语义分割)的局限以及解决方法
  18. 笔记——数据归一化 scikit-learn中的Scaler
  19. ylinux系统找到软件_你的 linux 上都有什么值得推荐的软件?
  20. 已故女孩在微博“复生”追星,你的数据资产谁说了算?

热门文章

  1. 编程是一门实践性的科学
  2. 542. 01 Matrix
  3. [剑指offer]面试题第[43]题[Leetcode][第233题][JAVA][1~n整数中1出现的次数][找规律][递归]
  4. [Leetcode][JAVA]第[29]题[两数相除][二分法]
  5. [国密算法]一文了解国密算法
  6. c语言笔记之数组和指针(初学者)
  7. mysql 3_mysql3
  8. 1282B1. K for the Price of One (Easy Version)
  9. wpf的listbox循环数据滚动_滚动版 CentOS Stream 和 Fedora 的关系
  10. OpenGL 4.0 Tutorials 第三章:初始化 OpenGL 4.0