要么去体育馆,要么去比赛,要么闲在家里

给出每一天体育馆和比赛的有无情况,要求连续两天不能去同一个地方

问最少闲几天

DP方程很容易看出

  dp(第i天能去的地方) = min(dp(第i-1天的三种情况)) ;

  dp(第i天呆在家里) = min(dp(第i-1天的三种情况))+1;

 #include <cstdio>
#include <iostream>
using namespace std;
#define inf 0x3f3f3f3f
int a[],ans[][],n;
void dfs()
{
ans[][]=ans[][]=ans[][]=;
for(int i=;i<=n;i++)
{
if(a[i]==)
{
ans[i][]=inf;
ans[i][]=inf;
}
else if(a[i]==)
{
ans[i][]=inf;
ans[i][]=min(ans[i-][],ans[i-][]);
}
else if(a[i]==)
{
ans[i][]=inf;
ans[i][]++;
ans[i][]=min(ans[i-][],ans[i-][]);
}
else
{
ans[i][]=min(ans[i-][],ans[i-][]);
ans[i][]=min(ans[i-][],ans[i-][]);
}
ans[i][]=min(ans[i-][],ans[i-][]);
ans[i][]=min(ans[i][],ans[i-][]);
ans[i][]++;
}
}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
}
dfs();
int res=min(ans[n][],ans[n][]);
res=min(res,ans[n][]);
printf("%d\n",res);
}

CodeForces 698A - Vacations (Codeforces Round #363 (Div. 2))的更多相关文章

  1. Codeforces Round 363 Div. 1 (A,B,C,D,E,F)

    Codeforces Round 363 Div. 1 题目链接:## 点击打开链接 A. Vacations (1s, 256MB) 题目大意:给定连续 \(n\) 天,每天为如下四种状态之一: 不 ...

  2. Codeforces Round #363 (Div. 2) C. Vacations —— DP

    题目链接:http://codeforces.com/contest/699/problem/C 题解: 1.可知每天有三个状态:1.contest ,2.gym,3.rest. 2.所以设dp[i] ...

  3. Codeforces Round #363 (Div. 2)->C. Vacations

    C. Vacations time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  4. Codeforces Round #363 (Div. 2) C. Vacations(DP)

    C. Vacations time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  5. Codeforces Round #363 (Div. 2)

    A题 http://codeforces.com/problemset/problem/699/A 非常的水,两个相向而行,且间距最小的点,搜一遍就是答案了. #include <cstdio& ...

  6. Codeforces Round #363 (Div. 1) B. Fix a Tree 树的拆环

    题目链接:http://codeforces.com/problemset/problem/698/B题意:告诉你n个节点当前的父节点,修改最少的点的父节点使之变成一棵有根树.思路:拆环.题解:htt ...

  7. Codeforces Round #363 (Div. 2) D. Fix a Tree —— 并查集

    题目链接:http://codeforces.com/contest/699/problem/D D. Fix a Tree time limit per test 2 seconds memory ...

  8. Codeforces Round #363 (Div. 2) B. One Bomb —— 技巧

    题目链接:http://codeforces.com/contest/699/problem/B 题解: 首先统计每行每列出现'*'的次数,以及'*'出现的总次数,得到r[n]和c[m]数组,以及su ...

  9. Codeforces Round #363 Div.2[111110]

    好久没做手生了,不然前四道都是能A的,当然,正常发挥也是菜. A:Launch of Collider 题意:20万个点排在一条直线上,其坐标均为偶数.从某一时刻开始向左或向右运动,速度为每秒1个单位 ...

随机推荐

  1. Sql server 数据库 单用户切换为多用户

    使用master 下的sysprocesses 查询 db正在使用的spid 如 select spid from sysprocesseswhere dbid=DB_ID('DbName') 然后执 ...

  2. mysql中查看字符集的cmd指令

    参看下面链接:http://blog.chinaunix.net/uid-20180960-id-1972668.html

  3. linux下tar用法

    以下是linux下tar的用法,转一下,以便方便自己看(这里没把rar,zip类的转过来,一般rar,zip在linux下基本没人用,基本上是zip,unzip,rar,unrar,这些命令,并且ra ...

  4. javascript get获取参数

    function GetQueryString(name) { var reg = new RegExp("(^|&)"+ name +"=([^&]*) ...

  5. Strategic game(POJ 1463 树形DP)

    Strategic game Time Limit: 2000MS   Memory Limit: 10000K Total Submissions: 7490   Accepted: 3483 De ...

  6. class Core<T> where T : class, new() 求解

    where T:泛型约束,约束类型T必须具有无参的构造函数表示T必须是class类型或它的派生类.new()构造函数约束允许开发人员实例化一个泛型类型的对象. 一般情况下,无法创建一个泛型类型参数的实 ...

  7. Qt中调用PolarSSL库(一)

    最近一直在学习SSL相关的知识,也是先了解理论相关的知识,主要是SSL相关的基本概念和连接建立过程,主要是基于PolarSSL开源库进行学习.学习完了之后就希望能给有所运用,就想用Qt写一个简单的程序 ...

  8. Json之语法,格式

    JSON 文本格式在语法上与创建 JavaScript 对象的代码相同.由于这种相似性,无需解析器,JavaScript 程序能够使用内建的 eval() 函数,用 JSON 数据来生成原生的 Jav ...

  9. linux source命令学习

    1. linux source命令的作用? 我们可能经常需要修改到诸如/etc/profile,~/.bash_profile等这样的配置文件, 一方面我们希望所作的修改在当前的环境中立即生效: 另一 ...

  10. Linux系统编程(13)——Shell的基本语法

    按照惯例,Shell变量由全大写字母加下划线组成,有两种类型的Shell变量:环境变量和本地变量. 环境变量: 环境变量可以从父进程传给子进程,因此Shell进程的环境变量可以从当前Shell进程传给 ...