题目描述

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. 支付宝APP支付,提示代码 ALIN10070

    ALIN10070 此代码时ALI64代码拆分后的细分代码: 代表签名验证失败等相关问题: 如果近期修改过或者续签 过签约协议,也需要更新公私钥.

  2. 数学:拓展Lucas定理

    拓展Lucas定理解决大组合数取模并且模数为任意数的情况 大概的思路是把模数用唯一分解定理拆开之后然后去做 然后要解决的一个子问题是求模质数的k次方 将分母部分转化成逆元再去做就好了 这里贴一份别人的 ...

  3. OpenResty 扩展库(二)lua-resty-template

    Lua和OpenResty的模板引擎(HTML) 模板语法 您可以在模板中使用以下标签: {{expression}},写入表达式的结果 - html转义 {*expression*},写入表达结果 ...

  4. ubuntu中mysql中文乱码及用python3.x调用

    首先声明解决方法也是网上找来的,知识自己记下来以防以后用到.   ubuntu版本是14.04使用apt-get命令安装mysql sudo apt-get install mysql-server ...

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

    20155212 2016-2017-2 <Java程序设计>第8周学习总结 教材学习内容总结 Chapter14 1. Channel架构与操作 想要取得Channel的实作对象,可以使 ...

  6. [BZOJ 1879][SDOI 2009]Bill的挑战 题解(状压DP)

    [BZOJ 1879][SDOI 2009]Bill的挑战 Description Solution 1.考虑状压的方式. 方案1:如果我们把每一个字符串压起来,用一个布尔数组表示与每一个字母的匹配关 ...

  7. tf.range()函数

    range()函数用于创建数字序列变量,有以下两种形式: range(limit, delta=1, dtype=None, name='range') range(start, limit, del ...

  8. Chrome插件:gitlab activity dashboard background-color

    背景 我一般都是在activity dashboard页看同事的提交记录,这样只要我有权限的项目有人提交了我就能够知道,虽然提交的具体代码压根不看.......但至少能够了解各个项目的开发情况(如果大 ...

  9. 分享一个C#创建Barcode的DLL

    用于工作需要产生Barcode,随手从网上找了一个DLL(原文地址忘了) http://files.cnblogs.com/panchunting/barcode_bin.zip 使用非常简单,只需添 ...

  10. springboot:mybatis多数据源配置

    1.application.properties #CMS数据源(主库) spring.datasource.cms.driver-class-name=com.mysql.jdbc.Driver s ...