CodeForces 698A - Vacations (Codeforces Round #363 (Div. 2))
要么去体育馆,要么去比赛,要么闲在家里
给出每一天体育馆和比赛的有无情况,要求连续两天不能去同一个地方
问最少闲几天
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))的更多相关文章
- Codeforces Round 363 Div. 1 (A,B,C,D,E,F)
Codeforces Round 363 Div. 1 题目链接:## 点击打开链接 A. Vacations (1s, 256MB) 题目大意:给定连续 \(n\) 天,每天为如下四种状态之一: 不 ...
- 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] ...
- 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 ...
- 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 ...
- Codeforces Round #363 (Div. 2)
A题 http://codeforces.com/problemset/problem/699/A 非常的水,两个相向而行,且间距最小的点,搜一遍就是答案了. #include <cstdio& ...
- Codeforces Round #363 (Div. 1) B. Fix a Tree 树的拆环
题目链接:http://codeforces.com/problemset/problem/698/B题意:告诉你n个节点当前的父节点,修改最少的点的父节点使之变成一棵有根树.思路:拆环.题解:htt ...
- 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 ...
- Codeforces Round #363 (Div. 2) B. One Bomb —— 技巧
题目链接:http://codeforces.com/contest/699/problem/B 题解: 首先统计每行每列出现'*'的次数,以及'*'出现的总次数,得到r[n]和c[m]数组,以及su ...
- Codeforces Round #363 Div.2[111110]
好久没做手生了,不然前四道都是能A的,当然,正常发挥也是菜. A:Launch of Collider 题意:20万个点排在一条直线上,其坐标均为偶数.从某一时刻开始向左或向右运动,速度为每秒1个单位 ...
随机推荐
- Ajax与ashx异步请求的简单案例
Ajax与ashx异步请求的简单案例: 前台页面(aspx): <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//E ...
- [Leetcode] Longest Substring Without Repeating Characters (C++)
题目: Given a string, find the length of the longest substring without repeating characters. For examp ...
- discuz x2 个人资料项排序问题解决方法、添加自定义字段、修改栏目名称和介绍
第一次写文章,希望与人提供方便同时,别误人子弟,自己研究的,大家看不懂只改文件就可以了,如果发现不对的地方请回复或直接通知我,谢谢,本来想在discuz论坛上发的,不懂版规也没时间看版规,怕发错,隔小 ...
- 存储过程使用表变量或临时表代替游标Fetch实例,访问远程数据库
定义表变量是可以直接操作在内存中的数据,比较快.临时表在大数据量时会比游标使用的资源少.还是要看具体情况了.也有可能在实际优化过程中相互替换呢. 留作记忆的代码如下: if object_id('te ...
- js入门基础7-2 (求模-隔行变色)
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- PROCEDURE_监测系统_告警信息存储过程—产生告警信息插入告警表
create or replace procedure proc_alarmlog(in_id in number, --采集器编码 ...
- Find them, Catch them(POJ 1703 关系并查集)
Find them, Catch them Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 38668 Accepted: ...
- php设置和获取变量类型
1. 获取变量类型 gettype($a); 2. 设置变量类型 settype($a,'int'); 3. 测试函数 is_array();是否数组 is_string();是否字符串 is_obj ...
- USB系列之三:从你的U盘里读出更多的内容
U盘是我们最常使用的一种USB设备,本文继续使用DOSUSB做驱动,试图以读取扇区的方式读取你的U盘.本文可能涉及的协议可能会比较多. 一.了解你的U盘 首先我们用上一篇文章介绍的程序usbvi ...
- .net 反编译利器 dnspy
Binaries Latest release: https://github.com/0xd4d/dnSpy/releases Latest build (possibly unstable): h ...