Codeforces Round #363 (Div. 2) [C] Vacations
来源:互联网 发布:批判性思维工具 知乎 编辑:程序博客网 时间:2024/06/05 15:30
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:
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.
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 <string.h>#include <stdlib.h>#include <time.h>#include <math.h>#include <iostream>#include <algorithm>#include <string>#include <set>#include <map>#include <queue>#include <stack>#include <vector>#include <bitset>using namespace std;#define bll long long#define dou double#define For(i,a,b) for (int i=(a),_##i=(b); i<=_##i; i++)#define Rof(i,a,b) for (int i=(a),_##i=(b); i>=_##i; i--)#define rep(i,a,b) for (int i=(a),_##i=(b); i<=_##i; i++)#define rek(i,a,b) for (int i=(a),_##i=(b); i>=_##i; i--)#define Mem(a,b) memset(a,b,sizeof(a))#define Cpy(a,b) memcpy(a,b,sizeof(b))//__builtin_popcountllconst int maxn=100+10,oo=1<<30;int N,A[maxn],F[maxn][3];int main(int argc, char* argv[]){ for (; scanf("%d",&N)!=EOF; ) { For(i,1,N) scanf("%d",&A[i]); For(i,1,N) For(j,0,2) F[i][j]=oo; F[0][2]=0; For(i,1,N) { For(j,0,2) if (F[i-1][j]!=oo) { if ((A[i]&1) && j!=0) F[i][0]=min(F[i][0],F[i-1][j]); if ((A[i]&2) && j!=1) F[i][1]=min(F[i][1],F[i-1][j]); F[i][2]=min(F[i][2],F[i-1][j]+1); } } int ans=min(F[N][0],min(F[N][1],F[N][2])); printf("%d\n",ans); } return 0;}
- Codeforces Round #363 (Div. 2) C. Vacations
- Codeforces Round #363 (Div. 2) [C] Vacations
- Codeforces Round #363 (Div. 2) C. Vacations
- Codeforces Round #363 C (Div. 2) Vacations
- Codeforces Round #363 (Div. 2) C. Vacations
- Codeforces Round #363 (Div. 2) C. Vacations
- Codeforces Round #363 (Div. 2)C. Vacations
- Codeforces Round #363 (Div. 2) C. Vacations
- Codeforces Round #363 (Div. 2) C Vacations
- Codeforces Round #363 (Div. 2) C. Vacations(DP)
- Codeforces Round #363 (Div. 2) C. Vacations(DP 动态规划)
- Codeforces Round #363 (Div. 2) C. Vacations(DP)
- Codeforces Round #363 (Div. 2) C. Vacations(逻辑运算)
- ****Codeforces Round #363 (Div. 2) C. Vacations(DP 动态规划)
- Codeforces Round #363 (Div. 2) C. Vacations (DP)
- Codeforces Round #363 (Div. 2) C. Vacations 贪心+dp
- Codeforces Round #363 (Div. 2) C. Vacations —— DP
- Codeforces#363 (Div. 2) C.Vacations
- POJ 3320 Jessica's Reading Problem
- 字节对齐详解
- 应用内跳转百度,高德地图
- 【题】【矩阵】NKOJ 1901 喜欢奇数的面包师
- java基础学习(5)疯狂java讲义第4章课后习题解答源码
- Codeforces Round #363 (Div. 2) [C] Vacations
- Leetcode Sort Colors
- java 多态,向上转型,向下转型(强制转换)之间的理解(学习笔记而已,不一定全部准确)
- Python下安装Numpy,Scipy,Matlotlib
- Activity四种启动模式
- 唐巧: 成长为 iOS 大 V 的秘密
- 最佳点割集
- 栈和队列面试题之--实现一个有getMin功能的栈
- 关于CAShapeLayer的一些实用案例和技巧