C. Vacations
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

#include<stdio.h>
#include<iostream>
using namespace std;
int max(int a,int b,int c){
int tmp;
tmp=(a>=b)?a:b;
tmp=(tmp>=c)?tmp:c;
return tmp; }
int max(int a,int b){
int tmp;
tmp=(a>=b)?a:b;
return tmp;
}
int main(){
int n;
scanf("%d",&n);
int dp[][];
int a[];
int ans=-;
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
}
for(int i=;i<=n;i++){
for(int j=;j<;j++) dp[i][j]=;
}
dp[][]=;
dp[][]=;
dp[][]=;
for(int i=;i<=n;i++){
if(a[i]==){
dp[i][]=max(dp[i-][],dp[i-][],dp[i-][]);
dp[i][]=max(dp[i-][],dp[i-][],dp[i-][]);
dp[i][]=max(dp[i-][],dp[i-][],dp[i-][]);
}else if(a[i]==){
dp[i][]=max(dp[i-][],dp[i-][],dp[i-][]);
dp[i][]=max(dp[i-][],dp[i-][],dp[i-][]);
dp[i][]=max(dp[i-][]+,dp[i-][]+,dp[i-][]); }else if(a[i]==){ dp[i][]=max(dp[i-][],dp[i-][],dp[i-][]);
dp[i][]=max(dp[i-][]+,dp[i-][]+,dp[i-][]);
dp[i][]=max(dp[i-][],dp[i-][],dp[i-][]); }else if(a[i]==){ dp[i][]=max(dp[i-][],dp[i-][],dp[i-][]);
dp[i][]=max(dp[i-][]+,dp[i-][]+,dp[i-][]);
dp[i][]=max(dp[i-][]+,dp[i-][]+,dp[i-][]); }
} for(int i=;i<=n;i++){
for(int j=;j<;j++)
ans=max(dp[i][j],ans);
}
printf("%d\n",n-ans);
return ;
}

dp可以的,但是麻烦。

贪心:对于每一天,尽量不休息。最后输出结果。

cf #363 c的更多相关文章

  1. cf #363 d

      time limit per test 2 seconds memory limit per test 256 megabytes input standard input output stan ...

  2. cf #363 b

    B. One Bomb time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  3. cf #363 a

    A. Launch of C time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  4. ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'

    凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...

  5. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  6. cf Round 613

    A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...

  7. ARC下OC对象和CF对象之间的桥接(bridge)

    在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...

  8. [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现

    1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...

  9. CF memsql Start[c]UP 2.0 A

    CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...

随机推荐

  1. 【树链剖分】【线段树】bzoj3083 遥远的国度

    记最开始的根为root,换根之后,对于当前的根rtnow和询问子树U而言, ①rtnow==U,询问整棵树 ②fa[rtnow]==U,询问除了rtnow所在子树以外的整棵树 ③rtnow在U的子树里 ...

  2. 1.4(学习笔记)JSP自定义标签

    一.JSP自定义标签 JSP自定义标签,可以通过实现Tag接口.继承TagSupport类来设置标签功能. 后续通过配置文件将标签和具体的实现类关联. 二.自定义第一个标签(实现Tag接口) 自定义标 ...

  3. Problem A: 调用函数,求三个数中最大数

    #include<stdio.h> int max(int a,int b,int c); int main() { int a,b,c; while(scanf("%d %d ...

  4. FireDac Pooling

    1.建立FDManager的ConnectionDef.并设置此Pooling为True. 2.建立Thread类进行多个FDConnection连接DB. 3.本列是oracle远程数据.如下图: ...

  5. maven-pom-build

    地址: http://blog.csdn.net/taiyangdao/article/details/52374125

  6. 用fastjson反序列化 带泛型的类

    ServiceResult<User> serviceResult = JSON.parseObject(obtainResult, new TypeReference<Servic ...

  7. CentOS 6.9使用Setup配置网络(解决dhcp模式插入网线不自动获取IP的问题)

    说明:dhcp模式插入网线不自动获取IP是因为网卡没有激活,造成这种原因的,应该是安装系统时没有插入网线造成的. 解决方法: 修改网卡配置文件 vim /etc/sysconfig/network-s ...

  8. 解决ThinkPHP3.2.3框架,PDO驱动查询出来的字段名全是小写的bug

    找到文件:ThinkPHP\Library\Think\Db\Driver.class.php 找到代码: // PDO连接参数 protected $options = array( PDO::AT ...

  9. PHP empty()函数:Can't use method return value in write context

    <?php if (!empty (get_gpc('userId'))) { $userId = get_gpc('userId'); } else { $error = "ID d ...

  10. delphi设计浮动窗口

    delphi设计浮动窗口 用过Photoshop的朋友一定对它的那些方便的浮动面板记忆犹新,其实这些面板就是一个个的小窗体,但这些小窗体都放在Photoshop的主窗体上 (不是存在主窗体中),有自己 ...