cf #363 c
1 second
256 megabytes
standard input
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.
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.
#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的更多相关文章
- cf #363 d
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output stan ...
- cf #363 b
B. One Bomb time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- cf #363 a
A. Launch of C time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- 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 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- cf Round 613
A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...
- ARC下OC对象和CF对象之间的桥接(bridge)
在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...
- [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现
1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...
- 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 ...
随机推荐
- 金融应用,计算酬金 Exercise06_11
/** * @author 冰樱梦 * 时间:2018年下半年 * 题目:金融应用,计算酬金 * */ public class Exercise06_11 { public static void ...
- 【R笔记】apply函数族
(1) apply apply函数通过对数组,矩阵,或非空维数值的数据框的“边缘”(margin)即行或列运用函数.返回值为向量,数组或列表. 函数形式 apply(X, MARGIN, ...
- gzip压缩目录
很遗憾,gzip不能针对整个目录进行压缩,只能递归压缩目录下的每一个文件. 当然,替代方案是只用tar进行打包,比如 tar cfz dir.tar.gz dirname
- Ubuntu 16.04下使用UNetbootin制作的ISO镜像为U盘启动出现:Missing Operating System (mbr.bin)
通过以下方式进行排查: 1.确定U盘是否真的有启动系统 2.分区是否已经标记为激活状态,尤其使用了Fdisk进行分区时,如果分区>=2时默认是不设置激活分区. 比如下面是通过Fdisk进行设置分 ...
- 分析器错误 未能加载类型“XX.WebApiApplication”
解决方案,删除bin目录下内容(有单独使用dll的删除前请先备份) 清理解决方案并重新生成
- Nginx实现图片防盗链(referer指令)
什么是图片盗链 每张图片在浏览器中都有对应的图片地址,在浏览器中输入这个地址是可以直接拿到图片. 图片盗链,就是盗用者在他的站上需要显示我们的图片,他没有把图片拿下来,放到他的服务器上, 而是直接 ...
- 【sql】sql优化
sql优化: 1.最左前缀原则 如果contact表上的tenement_id列创建了索引,那么查询的时候将索引列放在最左边,查询的速度会快很多,因为扫描的范围是索引范围而不是整张表范围!! SELE ...
- Bootstrap幻灯片
Bootstrap幻灯片的制作利用到了Carousel插件,包含:左右箭头.图片.点点导航 <div id="carousel-example-generic" class= ...
- C#断点续传
我们经常使用下载工具,如bit精灵.迅雷.FlashGet,这些软件都支持断点续传. 断点续传即下载任务暂停后可以继续,而无需重新下载,即下载时需要通知服务器的起始位置.如果允许多线程进行分片下载,必 ...
- 自己做的roguelike+恶魔城游戏《魔塔猎人》已发布。
游戏仍然是标准的roguelike,死亡后回到出生点重新开始,宏观架构上参考了<死亡细胞>,战斗设计上更加强调轻重攻击的组合,再配合236和28系列的搓招技.空中的突进飞腿.副武器等等. ...