题目链接:http://codeforces.com/problemset/problem/699/C


C. Vacations

time limit per test1 second
memory limit per test256 megabytes

Problem 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 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:

  1. ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out;
  2. ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out;
  3. ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out;
  4. 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:
6. to do sport on any two consecutive days,
7. to write the contest on any two consecutive days.

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.


这是一个简单的dp,然而完全没想到,模拟也可以做。
dp[i][j] (i:第几天,j:昨天干了啥) = 从第1天到第n天最少休息了多少天。


简单模拟:

#include<bits/stdc++.h>
using namespace std;
const int maxn = 110;
int num[maxn];
bool z[maxn];//用于标记前一天是否是休假
int main()
{int n;while(scanf("%d",&n)!= EOF){memset(z,0,sizeof(z));for(int i=1;i<=n;i++)scanf("%d",&num[i]);int ans = 0;bool flag = false;bool flag2 = false;for(int i=1;i<=n;i++){int now = ans;if(num[i] == 0)ans++;else if(num[i] == 1){if(num[i-1] == 3 && num[i-2] == 2 && i-2 > 0 && !z[i-1] && !z[i-2])ans++;else if(num[i-1] == 1 && !z[i-1] && i-1 >0)ans++;}else if(num[i] == 2){if(num[i-1] == 3 && num[i-2] == 1 && i-2 > 0 && !z[i-1] && !z[i-2])ans++;else if(num[i-1] == 2 && !z[i-1] && i-1 > 0)ans++;}if(num[i] == 3 && num[i-1] == 1 && !z[i-1])num[i] = 2;else if(num[i] == 3 && num[i-1] == 2 && !z[i-1])num[i] = 1;if(ans > now)z[i] = true;}printf("%d\n",ans);}return 0;
}

用dp做:

#include<bits/stdc++.h>
using namespace std;
const int maxn = 110;
int dp[maxn][10];
int num[maxn];
int main()
{int n;while(scanf("%d",&n) != EOF){memset(dp,0x7f,sizeof(dp));for(int i=0;i<=4;i++)dp[0][i] = 0;for(int i=1;i<=n;i++){int temp;scanf("%d",&temp);dp[i][0] = min(dp[i-1][1],min(dp[i-1][2],dp[i-1][0])) + 1;//前一天是休假,今天的dp++;if(temp == 1)dp[i][2] = min(dp[i-1][0],dp[i-1][1]);//今天做1,昨天做2或者休假if(temp == 2)dp[i][1] = min(dp[i-1][0],dp[i-1][2]);//今天做2,昨天做1或者休假if(temp == 3){dp[i][2] = min(dp[i-1][0],dp[i-1][1]);dp[i][1] = min(dp[i-1][0],dp[i-1][2]);}}printf("%d\n",min(dp[n][1],min(dp[n][2],dp[n][0])));}return 0;
}

转载于:https://www.cnblogs.com/GoldenFingers/p/9107249.html

CodeForces 699C - Vacations相关推荐

  1. codeforces 698A Vacations

    点击打开链接 A. Vacations time limit per test 1 second memory limit per test 256 megabytes input standard ...

  2. CodeForces 698A - Vacations (Codeforces Round #363 (Div. 2))

    要么去体育馆,要么去比赛,要么闲在家里 给出每一天体育馆和比赛的有无情况,要求连续两天不能去同一个地方 问最少闲几天 DP方程很容易看出 dp(第i天能去的地方) = min(dp(第i-1天的三种情 ...

  3. Codeforces #363 div2 prob699

    距离上次刷cf已经过去好久了吧 699ALaunch of Collider 大概题意 题解 代码 699BOne Bomb 大概题意 题解 代码 699C Vacations 大概题意 题解 代码 ...

  4. 【CF - 699C】 Vacations (日程安排 dp)

    题干: Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows ...

  5. CodeForces 375D Tree and Queries

    传送门:https://codeforces.com/problemset/problem/375/D 题意: 给你一颗有根树,树上每个节点都有其对应的颜色,有m次询问,每次问你以点v为父节点的子树内 ...

  6. 「日常训练」Bad Luck Island(Codeforces Round 301 Div.2 D)

    题意与分析(CodeForces 540D) 是一道概率dp题. 不过我没把它当dp做... 我就是凭着概率的直觉写的,还好这题不算难. 这题的重点在于考虑概率:他们喜相逢的概率是多少?考虑超几何分布 ...

  7. 【codeforces 812C】Sagheer and Nubian Market

    [题目链接]:http://codeforces.com/contest/812/problem/C [题意] 给你n个物品; 你可以选购k个物品;则 每个物品有一个基础价值; 然后还有一个附加价值; ...

  8. CodeForces 获得数据

    针对程序的输出可以看见 CodeForces :当输入.输出超过一定字符,会隐藏内容 所以:分若干个程序进行输入数据的获取 1. 1 for (i=1;i<=q;i++) 2 { 3 scanf ...

  9. codeforces水题100道 第二十七题 Codeforces Round #172 (Div. 2) A. Word Capitalization (strings)...

    题目链接:http://www.codeforces.com/problemset/problem/281/A 题意:将一个英文字母的首字母变成大写,然后输出. C++代码: #include < ...

最新文章

  1. 边框border属性总结
  2. c++ 12.一维数组冒泡排序
  3. OpenCV图像分割-watershed
  4. java创建线程哪种方法最好_Java创建线程的三种方法比较
  5. GraphX:基于Spark的弹性分布式图计算系统
  6. 用java在JPanel中建一个表格_如何使用Java在JPanel中显示JTable?
  7. python样本不均衡_三招提拔数据不均衡模子的机能(附python代码)
  8. set列表对象去重_set去重应用
  9. 简单使用WPE进行网页嗅探
  10. MDUI的黑暗模式实现和居中问题
  11. mysql 织梦 优化,织梦Dedecms全站SEO优化教程
  12. Android使用开源框架完成城市列表三级联动(从服务端获取数据源和自定义json数据源)
  13. 垃圾分类之上传一张图片进行测试
  14. win10 文件图标变白的解决方法
  15. 【JavaScript 教程】第六章 数组18—push() :将一个或多个元素添加到数组的末尾...
  16. ccc-sklearn-13-朴素贝叶斯(1)
  17. 海量数据实战(0)从两个文件50亿数据中找出相同的URL
  18. Python中小波工具(pywt)分析EEG数据
  19. 单片机课程设计,基于AT89C51和LCD-12864的贪吃蛇游戏
  20. 用matplotlib作图时,如何将坐标轴设置成对数坐标?

热门文章

  1. 01. 把存储过程结果集SELECT INTO到临时表
  2. mysql学习总结一:mysql的安装,介绍,基本命令操作
  3. Windows 7下Eclipse搭建Android开发环境
  4. 读《c#与算法--快速排序》随笔
  5. SAP S/4HANA销售订单创建时,会自动触发生产订单的创建
  6. Spring Cloud相关项目
  7. [机器学习] Coursera ML笔记 - 逻辑回归(Logistic Regression)
  8. 我之我见:samba共享
  9. 一些常用的图像数据库
  10. linux软件安装简介(apt和dpkg)