题目描述

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:

  1. on this day the gym is closed and the contest is not carried out;
  2. on this day the gym is closed and the contest is carried out;
  3. on this day the gym is open and the contest is not carried out;
  4. 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的更多相关文章

  1. 思维题--code forces round# 551 div.2

    思维题--code forces round# 551 div.2 题目 D. Serval and Rooted Tree time limit per test 2 seconds memory ...

  2. Code Forces 796C Bank Hacking(贪心)

    Code Forces 796C Bank Hacking 题目大意 给一棵树,有\(n\)个点,\(n-1\)条边,现在让你决策出一个点作为起点,去掉这个点,然后这个点连接的所有点权值+=1,然后再 ...

  3. Code Forces 833 A The Meaningless Game(思维,数学)

    Code Forces 833 A The Meaningless Game 题目大意 有两个人玩游戏,每轮给出一个自然数k,赢得人乘k^2,输得人乘k,给出最后两个人的分数,问两个人能否达到这个分数 ...

  4. CodeForces 698A Vacations

    题目链接 : http://codeforces.com/problemset/problem/698/A 题目大意: 阿Q有n天假期,假期中有三种安排 休息.健身.比赛.每天有三种选择条件: 0 健 ...

  5. Code Forces 543A Writing Code

    题目描述 Programmers working on a large project have just received a task to write exactly mm lines of c ...

  6. 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 ...

  7. code forces 382 D Taxes(数论--哥德巴赫猜想)

    Taxes time limit per test 2 seconds memory limit per test 256 megabytes input standard input output ...

  8. code forces Watermelon

    /* * Watermelon.cpp * * Created on: 2013-10-8 * Author: wangzhu */ /** * 若n是偶数,且大于2,则输出YES, * 否则输出NO ...

  9. code forces Jeff and Periods

    /* * c.cpp * * Created on: 2013-10-7 * Author: wangzhu */ #include<cstdio> #include<iostrea ...

随机推荐

  1. 流行的软件工程过程--Rational统一过程!

    RUP提供了一个给角色分配任务和责任的严格方法,在J2EE开发中使用RUP出于以下三个原因: RUP以架构为中心:在将资源分配给全面开发之前,它先开发一个可执行的架构原型. UP是迭代并基于构件的. ...

  2. CSS-3 box-shadow 的使用

    box-shadow是给对象实现图层阴影效果的. 语法: E {box-shadow: <length> <length> <length>?<length& ...

  3. 20155339 2016-2017-2 《Java程序设计》第5周学习总结

    20155339 2016-2017-2 <Java程序设计>第5周学习总结 教材学习内容总结 使用try.catch 使用try.catch语法,JVM会先尝试执行try区块中的代码,如 ...

  4. yii2框架目录

    框架目录结构 [目录] backend——后台web程序 common——公共的文件 console——控制台程序 environments——环境配置 frontend——前台web程序 [文件] ...

  5. 第5月第15天 php email

    1. <?php require_once "Mail.php"; $from = "luckyeggs<fuping304@163.com>" ...

  6. python垃圾回收之分代回收

    可参考vamei的博客和https://www.jianshu.com/p/1e375fb40506

  7. mysql集成部署

    经常听说mysql数据库是集成在系统中,也一直不太明白集成的概念.今天才明白集成的概念就是将mysql所有的文件放到一个文件夹下放到系统中,也就是将mysql采用目录迁移部署的方式进行安装.在上一篇研 ...

  8. 奈奎斯特定理 and 香农定理

    -----------------------整理自<21ic电子网> 奈奎斯特定理(Nyquist's Theorem)和香农定理(Shannon's Theorem)是网络传输中的两个 ...

  9. Linux驱动技术(四) _异步通知技术【转】

    转自:https://www.cnblogs.com/xiaojiang1025/p/6376561.html 异步通知的全称是"信号驱动的异步IO",通过"信号&quo ...

  10. tar.gz tar.bz2的解压命令

    .tar.gz     格式解压为          tar   -zxvf   xx.tar.gz .tar.bz2   格式解压为          tar   -jxvf    xx.tar.b ...