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. 【权值分块】bzoj3685 普通van Emde Boas树

    权值分块,虽然渐进复杂度不忍直视,但其极小的常数使得实际运行起来比平衡树快,大多数情况和递归版权值线段树差不多,有时甚至更快.但是被zkw线段树完虐. #include<cstdio> # ...

  2. 集合视图UICollectionView 介绍及其示例程序

    UICollectionView是一种新的数据展示方式,简单来说可以把它理解成多列的UITableView.如果你用过iBooks的话,可 能你还对书架布局有一定印象,一个虚拟书架上放着你下载和购买的 ...

  3. DOM系统学习-表格、样式和元素大小

    操作表格  属性: caption    标题元素 tHead    表头元素 tFoot    表尾元素 tBodies    主体元素集合,通过下标取 row    行元素集合,通过下标取  方法 ...

  4. mac下更新自带的PHP版本到5.6或7.0

    下载和安装PHP 5.6 打开终端并且运行如下命令: curl -s http://php-osx.liip.ch/install.sh | bash -s 5.6 然后,PHP 5.6的版本会被安装 ...

  5. VB6的UTF8编码解码

    'UTF-8编码  Public Function UTF8Encode(ByVal szInput As String) As String     Dim wch  As String     D ...

  6. js数据加载完成的方法

    1.document.onreadystatechange(页面加载完成的方法)配合document.readyState(获取加载状态)使用 document.onreadystatechange= ...

  7. No goals have been specified for this build 解决方案

    运行maven报错:[ERROR] No goals have been specified for this build. You must specify a valid lifecycle ph ...

  8. 深入解析淘宝Diamond之客户端架构

    转载:http://blog.csdn.net/u013970991/article/details/52088350 一.什么是Diamond diamond是淘宝内部使用的一个管理持久配置的系统, ...

  9. angular - 如何运行在起来 - 使用nginx

    nginx下载地址,使用的是标准版的: 点击下载nginx nginx下载完后,解压 dist文件夹下面所有angular文件放入html文件夹中. 最后命令行cd到当前nginx.exe目录,启动命 ...

  10. mui.fire() 和 mui.trigger()

    导读:添加自定义事件监听操作和标准js事件监听类似,可直接通过window对象添加,通过mui.fire()方法可触发目标窗口的自定义事件 监听自定义事件 添加自定义事件监听操作和标准js事件监听类似 ...