Codeforces Round #363 (Div. 2) C
Description
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 ndays: 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:
- on this day the gym is closed and the contest is not carried out;
- on this day the gym is closed and the contest is carried out;
- on this day the gym is open and the contest is not carried out;
- 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.
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.
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.
4
1 3 2 0
2
7
1 3 3 2 1 2 3
0
2
2 2
1
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[i][j]第i天做第j个事情,可以休息几天~
#include<bits/stdc++.h>
using namespace std;
int dp[1000][3];
int inf=(1<<31)-1;
int main()
{
int n;
int num[19999];
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>num[i];
for(int j=0;j<=3;j++)
{
dp[i][j]=inf;
}
}
for(int i=1;i<=n;i++)
{
if(num[i]==0)
{
dp[i][0]=min(dp[i-1][0],min(dp[i-1][1],dp[i-1][2]))+1;
}
if(num[i]==1)
{
dp[i][0]=min(dp[i-1][0],min(dp[i-1][1],dp[i-1][2]))+1;
dp[i][1]=min(dp[i-1][0],dp[i-1][2]);
}
if(num[i]==2)
{
dp[i][0]=min(dp[i-1][0],min(dp[i-1][1],dp[i-1][2]))+1;
dp[i][2]=min(dp[i-1][0],dp[i-1][1]);
}
if(num[i]==3)
{
dp[i][0]=min(dp[i-1][0],min(dp[i-1][1],dp[i-1][2]))+1;
dp[i][2]=min(dp[i-1][0],dp[i-1][1]);
dp[i][1]=min(dp[i-1][0],dp[i-1][2]);
}
}
int Min=inf;
for(int i=0;i<=3;i++)
{
Min=min(dp[n][i],Min);
}
cout<<Min<<endl;
return 0;
}
Codeforces Round #363 (Div. 2) C的更多相关文章
- Codeforces Round 363 Div. 1 (A,B,C,D,E,F)
Codeforces Round 363 Div. 1 题目链接:## 点击打开链接 A. Vacations (1s, 256MB) 题目大意:给定连续 \(n\) 天,每天为如下四种状态之一: 不 ...
- Codeforces Round #363 (Div. 2)
A题 http://codeforces.com/problemset/problem/699/A 非常的水,两个相向而行,且间距最小的点,搜一遍就是答案了. #include <cstdio& ...
- Codeforces Round #363 (Div. 1) B. Fix a Tree 树的拆环
题目链接:http://codeforces.com/problemset/problem/698/B题意:告诉你n个节点当前的父节点,修改最少的点的父节点使之变成一棵有根树.思路:拆环.题解:htt ...
- Codeforces Round #363 (Div. 2) D. Fix a Tree —— 并查集
题目链接:http://codeforces.com/contest/699/problem/D D. Fix a Tree time limit per test 2 seconds memory ...
- Codeforces Round #363 (Div. 2) B. One Bomb —— 技巧
题目链接:http://codeforces.com/contest/699/problem/B 题解: 首先统计每行每列出现'*'的次数,以及'*'出现的总次数,得到r[n]和c[m]数组,以及su ...
- Codeforces Round #363 (Div. 2) C. Vacations —— DP
题目链接:http://codeforces.com/contest/699/problem/C 题解: 1.可知每天有三个状态:1.contest ,2.gym,3.rest. 2.所以设dp[i] ...
- Codeforces Round #363 (Div. 2)A-D
699A 题意:在一根数轴上有n个东西以相同的速率1m/s在运动,给出他们的坐标以及运动方向,问最快发生的碰撞在什么时候 思路:遍历一遍坐标,看那两个相邻的可能相撞,更新ans #include< ...
- Codeforces Round #363 Div.2[111110]
好久没做手生了,不然前四道都是能A的,当然,正常发挥也是菜. A:Launch of Collider 题意:20万个点排在一条直线上,其坐标均为偶数.从某一时刻开始向左或向右运动,速度为每秒1个单位 ...
- Codeforces Round #363 (Div. 2) One Bomb
One Bomb 题意: 只有一个炸弹,并且一个只能炸一行和一列的'*',问最后能否炸完所以'*',如果可以输出炸弹坐标 题解: 这题做的时候真的没什么好想法,明知道b题应该不难,但只会瞎写,最后越写 ...
- 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 ...
随机推荐
- BZOJ1218:[HNOI2003]激光炸弹
我对状态空间的理解:https://www.cnblogs.com/AKMer/p/9622590.html 题目传送门:https://www.lydsy.com/JudgeOnline/probl ...
- docker-ce安装与搭建私有仓库
https://www.cnblogs.com/sszhou/p/7389144.html 系统环境centos7 ###docker-ce安装###1.卸载老版本,较老版本的Docker被称为doc ...
- shock编程
Socket接口是TCP/IP网络的API,Socket接口定义了许多函数或例程,程序员可以用它们来开发TCP/IP网络上的应用程序.要学Internet上的TCP/IP网络编程,必须理解Socket ...
- Python:urllib模块的urlretrieve方法
转于:https://blog.csdn.net/fengzhizi76506/article/details/59229846 博主:fengzhizi76506 1)功能: urllib模块提供的 ...
- selenium如何获取已定位元素的属性值?
HTML源代码: <div class="res-status" data-fortune="5" data-selfsos="" d ...
- Nios程序烧写到EPCS方法 - 第1页 - asus119's Blog - EDN China电子设计技术
Nios程序烧写到EPCS方法 - 第1页 - asus119's Blog - EDN China电子设计技术 这里主要是针对EP3C系列FPGA的Nios程序固化到EPCS中的方法做简要说明.硬件 ...
- Gpon与Epon的区别
一.GPON Gpon(Gigabit-Capable pon)技术起源于ATMPON技术标准,现已形成基于ITU-TG.984.X标准的最新一代宽带无源光综合接入标准. 1.GPON技术特点: 1. ...
- display与position之间的关系
以防自己忘记写的 网上找的 positon 与 display 的相互关系 元素分为内联元素和区块元素两类(当然也有其它的),在内联元素中有个非常重要的常识,即内两元素是不可以设置区块元素所具有的样式 ...
- Angular14 Visual Studio Code作为Angular开发工具常用插件安装、json-server安装与使用、angular/cli安装失败问题、emmet安装
前提准备: 搭建好Angular开发环境 1 安装Visual Studio Code 教程简单,不会的去问度娘 2 安装Chrome浏览器 教程简单,不会的趣闻度娘 3 Visual Studio ...
- Maven 命令格式及一些常用命令
Maven自身指定定义了一套对项目进行编译,测试,打包,运行,部署等工作的抽象.Maven自己是不实际负责这些工作的,而是把它们交给了插件.所以Maven命令的实际工作执行者是各种各样的插件. 要了解 ...