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 ...
随机推荐
- 5.9 j(java学习笔记)强软弱虚引用及WeakHashMap、IdentityHashMap、EnumMap
一.引用分类 强:运行垃圾回收机制后也不回收,程序出现内存溢出也不回收. 软:在垃圾回收机制运行时判断内存是否已满,如果内存已满则回收,内存充足则不回收. 弱:垃圾回收机制运行后不论内存是否充足都会立 ...
- 计算最大公约数 Exercise05_14
import java.util.Scanner; /** * @author 冰樱梦 * 时间:2018年下半年 * 题目:计算最大公约数 * */ public class Exercise05_ ...
- 十. 图形界面(GUI)设计9.列表和组合框
列表和组合框是又一类供用户选择的界面组件,用于在一组选择项目选择,组合框还可以输入新的选择. 列表 列表(JList)在界面中表现为列表框,是JList类或它的子类的对象.程序可以在列表框中加入多个文 ...
- hadoop InputFormat getSplits
/** Splits files returned by {@link #listStatus(JobConf)} when * they're too big.*/ public InputSpli ...
- ASP.NET Core 1.0基础之诊断
来源https://docs.asp.net/en/latest/fundamentals/diagnostics.html ASP.NET Core 1.0包含了一些新的特性来辅助诊断问题.可以在S ...
- JS中的import和require区别
1.import xx from yy的方式是静态编译,即编译时加载,要写在文件的最上头,但是import()函数可以实现动态加载,写在任何地方 2.require是动态加载,即运行时加载,理论上可以 ...
- C#之Hello World(入门 )
C#是一种简单.现代.面向对象和类型安全的编程语言. C#由C和C++发展而来.C#(英文发音C sharp)牢固地植根于C和C++语言族谱中,是Microsoft专门为使用.NET平台而创建的. • ...
- 开发板tftp:timeout问题
想要从PC上面tftp文件的时候遇到了tftp:timeout的问题: >: tftp -gr gprsapp 192.168.1.38tftp: timeout 检查了网络,可以ping的通P ...
- 解读Spark Streaming RDD的全生命周期
本节主要内容: 一.DStream与RDD关系的彻底的研究 二.StreamingRDD的生成彻底研究 Spark Streaming RDD思考三个关键的问题: RDD本身是基本对象,根据一定时间定 ...
- Druid对比Hadoop
Druid对比Hadoop Hadoop 向世界证明, 花费很少的钱实现典型的解决方案, 将数据保存在一般的商用机器的数据仓库里是可行的. 当人们将自己的数据保存在Hadoop, 他们发现两个问题 ...