Code Forces 698A Vacations
题目描述
Vasya has nn days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this nn days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the ii -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.
It is an easy DP but has a long DP funcation.
0 means rest, 1 means contest and 2 means sport.
Then the DP funcation come up quickly (i-1 means the last day):
if(day[i]==0) dp[i][0]=min(dp[i-1][0],min(dp[i-1][1],dp[i-1][2]))+1;
if(day[i]==1) 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(day[i]==2) 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(day[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]);
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define in(a) a=read()
#define REP(i,k,n) for(int i=k;i<=n;i++)
using namespace std;
inline int read(){
int x=,f=;
char ch=getchar();
for(;!isdigit(ch);ch=getchar())
if(ch=='-')
f=-;
for(;isdigit(ch);ch=getchar())
x=x*+ch-'';
return x*f;
}
int n,m;
int day[],dp[][];
int main(){
in(n);
memset(dp,,sizeof(dp));
REP(i,,n) in(day[i]);
dp[][]=dp[][]=dp[][]=;
REP(i,,n){
if(day[i]==) dp[i][]=min(dp[i-][],min(dp[i-][],dp[i-][]))+;
if(day[i]==) dp[i][]=min(dp[i-][],min(dp[i-][],dp[i-][]))+,dp[i][]=min(dp[i-][],dp[i-][]);
if(day[i]==) dp[i][]=min(dp[i-][],min(dp[i-][],dp[i-][]))+,dp[i][]=min(dp[i-][],dp[i-][]);
if(day[i]==) dp[i][]=min(dp[i-][],min(dp[i-][],dp[i-][]))+,dp[i][]=min(dp[i-][],dp[i-][]),dp[i][]=min(dp[i-][],dp[i-][]);
//cout<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2]<<endl;
}
cout<<min(dp[n][],min(dp[n][],dp[n][]));
return ;
}
Code Forces 698A Vacations的更多相关文章
- 思维题--code forces round# 551 div.2
思维题--code forces round# 551 div.2 题目 D. Serval and Rooted Tree time limit per test 2 seconds memory ...
- Code Forces 796C Bank Hacking(贪心)
Code Forces 796C Bank Hacking 题目大意 给一棵树,有\(n\)个点,\(n-1\)条边,现在让你决策出一个点作为起点,去掉这个点,然后这个点连接的所有点权值+=1,然后再 ...
- Code Forces 833 A The Meaningless Game(思维,数学)
Code Forces 833 A The Meaningless Game 题目大意 有两个人玩游戏,每轮给出一个自然数k,赢得人乘k^2,输得人乘k,给出最后两个人的分数,问两个人能否达到这个分数 ...
- CodeForces 698A Vacations
题目链接 : http://codeforces.com/problemset/problem/698/A 题目大意: 阿Q有n天假期,假期中有三种安排 休息.健身.比赛.每天有三种选择条件: 0 健 ...
- Code Forces 543A Writing Code
题目描述 Programmers working on a large project have just received a task to write exactly mm lines of c ...
- code forces 383 Arpa's loud Owf and Mehrdad's evil plan(有向图最小环)
Arpa's loud Owf and Mehrdad's evil plan time limit per test 1 second memory limit per test 256 megab ...
- code forces 382 D Taxes(数论--哥德巴赫猜想)
Taxes time limit per test 2 seconds memory limit per test 256 megabytes input standard input output ...
- code forces Watermelon
/* * Watermelon.cpp * * Created on: 2013-10-8 * Author: wangzhu */ /** * 若n是偶数,且大于2,则输出YES, * 否则输出NO ...
- code forces Jeff and Periods
/* * c.cpp * * Created on: 2013-10-7 * Author: wangzhu */ #include<cstdio> #include<iostrea ...
随机推荐
- css 基础1
css 层叠样式表 css手册 样式写在head 中间 style标签 css 样式规则: 选择器 {属性:属性值:属性:属性值} 字体样式属性:font-size 字号大小 color 字体颜色 f ...
- android studio run的时候一直卡在waiting for debug
原因如下: 选择ok就可以,同时我们也可以从这里找到 平常遇到跟真机有关的问题,三步大法,1,插拔手机,2.adb kill-server;adb start-server 3.重启as
- [转载]10款流行的Markdown编辑器
10款流行的Markdown编辑器 http://www.csdn.net/article/2014-05-05/2819623 作为一个开源人,如果你不会使用Markdown语法,那你就OUT了!M ...
- 20155328 2016-2017-2 《Java程序设计》 第8周学习总结
20155328 2016-2017-2 <Java程序设计> 第8周学习总结 教材学习内容总结 NIO与NIO2 认识NIO 相对于IO,NIO可以让你设定缓冲区容量,在缓冲区中对感兴趣 ...
- CodeForces 1059C
Description Let's call the following process a transformation of a sequence of length nn . If the se ...
- VIM 配置随手记
刚开始使用VIM, 主要想用它来写python. 目标是颜色比较舒适, 并且能够自动换行自动补全. .vimrc 设置 这是类似 .bashrc 的配置文件, vim 的各种配置都可以在里面实现. 一 ...
- CSS marging相关
一.margin可以为负值 在盒模型中,内容区的width/height.padding.border都不能为负值,但是margin例外,它可以为负值. margin负值的本质,在于它改变了元素在普通 ...
- Socket心跳包机制【转】
转自:https://blog.csdn.net/xuyuefei1988/article/details/8279812 心跳包的发送,通常有两种技术 方法1:应用层自己实现的心跳包 由应用程序自己 ...
- Linux DRM KMS 驱动简介【转】
转自:https://blog.csdn.net/yangkuanqaz85988/article/details/48689521 Whoops,上次写完<Linux DRM Graphic ...
- free vmstat查看内存及系统调优【转】
内存查看 查看内存是否存在瓶颈,使用top指令看比较麻烦,而free命令更为直观: [/home/weber#]free total used free shared buffers cached M ...