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 ...
随机推荐
- SPOJ 8222 NSUBSTR - Substrings
http://www.spoj.com/problems/NSUBSTR/ 题意: F(x)定义为字符串S中所有长度为x的子串重复出现的最大次数 输出F[1]~F[len(S)] 用字符串S构建后缀自 ...
- 优雅地搭建整合ssm项目
spring + spring mvc + mybatis 三大框架建议观看 黑马程序员出品的 Springmvc+Mybatis由浅入深全套视频教程 Spring框架2016版视频 观看顺序 ,我个 ...
- 机器学习:分类算法性能指标之ROC曲线
在介绍ROC曲线之前,先说说混淆矩阵及两个公式,因为这是ROC曲线计算的基础. 1.混淆矩阵的例子(是否点击广告): 说明: TP:预测的结果跟实际结果一致,都点击了广告. FP:预测结果点击了,但是 ...
- 10个造型奇特的css3进度条(有的html被编辑器转义了,上面的代码还是OK的)。。。转载
<div id="caseVerte"> <div id="case1"></div> <div id="c ...
- 以后的博客将更新到自己的域名pythonsite.com,欢迎访问
以后的博客将更新到自己的域名pythonsite.com,欢迎访问
- Android的layout_weight和weightSum
先看一下weightSum属性的功能描述:定义weight总和的最大值.如果未指定该值,以所有子视图的layout_weight属性的累加值作为总和的最大值.把weightSum的定义搁在这里,先去看 ...
- Javascript - 表达式与语句
表达式与语句(Expression&Statement) 流程控制语句 1.嵌入式语句 嵌入式即这种语句可以无限嵌套N层.所有嵌入式语句只需要键入首个关键单词,在visual studio里按 ...
- python-super1
一.问题的发现与提出 一般子类在继承父类后,若子类覆盖了父类,则只执行子类,不执行父类.如果没有,则执行父类代码. 发现使用super()后,子类,父类都会执行,比较疑惑,记录学习,super知识点 ...
- 洛谷 P3320: bzoj 3991: LOJ 2182: [SDOI2015]寻宝游戏
题目传送门:LOJ #2182. 题意简述: 一棵 \(n\) 个节点的树,边有边权. 每个点可能是关键点,每次操作改变一个点是否是关键点. 求所有关键点形成的极小联通子树的边权和的两倍. 题解: 有 ...
- mysql学习------二进制日志管理
MySQL二进制日志(Binary Log) a.它包含的内容及作用如下: 包含了所有更新了数据或者已经潜在更新了数据(比如没有匹配任何行的一个DELETE) 包含关于每个更新数据库( ...