题目链接:http://codeforces.com/problemset/problem/698/A

题意

Vasya在n天中,有三件事情可以做,健身、比赛或者休息,但是不能连续两天都是比赛或都是但是健身,但是连续休息两天是允许的,问题是在这n天中,Vasya最少可以休息几天?

0代表休息,1代表比赛,2代表健身,3可以代表比赛也可以代表健身

思路

用数组dp[i][j]表示第i天做活动j,数值表示最小休息的天数

状态转移方程:

对于0: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])

对于2:dp[i][2]=min(dp[i-1][0],dp[i-1][1])

对于3,就是求dp[i][1]和dp[i][2]

AC代码

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <string>
#define ll long long
#define pi acos(-1.0)
#define INF 0x3f3f3f3f
#define ms(a) memset(a,INF,sizeof(a))
const double E=exp(1);
const int maxn=1e5+10;
using namespace std;
//dp[i][j]表示第i天做了事件j,其数值代表从第1天到第i天的最小休息天数
int dp[maxn][10];
int main(int argc, char const *argv[])
{
ios::sync_with_stdio(false);
int n;
cin>>n;
int m;
ms(dp);
dp[0][0]=0;
for(int i=1;i<=n;i++)
{
cin>>m;
//继承昨天的最小休息天数,并在这一天使休息天数+1。相当于输入m=0的状态
dp[i][0]=min(dp[i-1][0],min(dp[i-1][1],dp[i-1][2]))+1;
//判断输入的事件。并更新最小休息天数
if(m==1)
dp[i][1]=min(dp[i-1][2],dp[i-1][0]);
if(m==2)
dp[i][2]=min(dp[i-1][1],dp[i-1][0]);
if(m==3)
{
dp[i][1]=min(dp[i-1][2],dp[i-1][0]);
dp[i][2]=min(dp[i-1][1],dp[i-1][0]);
}
}
cout<<min(dp[n][0],min(dp[n][1],dp[n][2]))<<endl;
return 0;
}

Codeforces 698A:Vacations(DP)的更多相关文章

  1. Codeforces Gym101341K:Competitions(DP)

    http://codeforces.com/gym/101341/problem/K 题意:给出n个区间,每个区间有一个l, r, w,代表区间左端点右端点和区间的权值,现在可以选取一些区间,要求选择 ...

  2. POJ 2192 :Zipper(DP)

    http://poj.org/problem?id=2192 Zipper Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1 ...

  3. HDU 5791:Two(DP)

    http://acm.hdu.edu.cn/showproblem.php?pid=5791 Two Problem Description   Alice gets two sequences A ...

  4. codeforces 711C Coloring Trees(DP)

    题目链接:http://codeforces.com/problemset/problem/711/C O(n^4)的复杂度,以为会超时的 思路:dp[i][j][k]表示第i棵数用颜色k涂完后bea ...

  5. codeforces#1154F. Shovels Shop (dp)

    题目链接: http://codeforces.com/contest/1154/problem/F 题意: 有$n$个物品,$m$条优惠 每个优惠的格式是,买$x_i$个物品,最便宜的$y_i$个物 ...

  6. Codeforces 1051 D.Bicolorings(DP)

    Codeforces 1051 D.Bicolorings 题意:一个2×n的方格纸,用黑白给格子涂色,要求分出k个连通块,求方案数. 思路:用0,1表示黑白,则第i列可以涂00,01,10,11,( ...

  7. Codeforces 1207C Gas Pipeline (dp)

    题目链接:http://codeforces.com/problemset/problem/1207/C 题目大意是给一条道路修管道,相隔一个单位的管道有两个柱子支撑,管道柱子高度可以是1可以是2,道 ...

  8. Codeforces 704C - Black Widow(dp)

    Codeforces 题目传送门 & 洛谷题目传送门 u1s1 感觉这种题被评到 *2900 是因为细节太繁琐了,而不是题目本身的难度,所以我切掉这种题根本不能说明什么-- 首先题目中有一个非 ...

  9. POJ 1260:Pearls(DP)

    http://poj.org/problem?id=1260 Pearls Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8 ...

随机推荐

  1. Android 利用ViewPager、Fragment、PagerTabStrip实现多页面滑动效果

    本文主要介绍如何利用ViewPager.Fragment.PagerTabStrip实现多页面滑动效果.即google play首页.新浪微博消息(at.评论.私信.广播)页面的效果.ViewPage ...

  2. python-GUI,生成ssn

    第一次做这个, 样子有点丑,主要是实现功能,做测试的时候,经常要用到身份证号.手机号.姓名等,这里先生成ssn,后续研究怎么做成客户端 代码: from tkinter import * from u ...

  3. 肠道型(enterotype)简介

    An enterotype is a classification of living organisms based on its bacteriological ecosystem in the ...

  4. Sergey's problem CodeForces - 1019C (图论,构造,神题)

    链接 大意: 给定有向图, 求选择一个点集$S$, 使得$S$任意两点不相连, 且对于不属于$S$的任意点$x$, 均存在$S$中的点$y$, 使得$d(x,y)<=2$, $d(x,y)$为从 ...

  5. 第一个 MVC 应用程序(上半部分)(《精通 ASP.NET MVC5》 的第二章)

    本章将使用 ASP.NET MVC 框架创建一个简单的数据录入应用程序. 笔者会将过程分解成一个个的步骤,以便能够看出如何构造 ASP.NET MVC 应用程序.(对于一些未进行解释的内容,笔者提供了 ...

  6. JavaScript In OA Framework

    原文地址:JavaScript In OA Framework (需FQ) “To be or not to be…… is the question…..!” The famous soliloqu ...

  7. IOS8-人机界面指南

    [ISUX转译]iOS 8人机界面指南(一):UI设计基础 糖箔糊2014.09.23 文章索引 1.1 为iOS而设计(Designing for iOS) 1.1.1 以内容为核心(Defer t ...

  8. CentOS 7中firewall防火墙详解和配置以及切换为iptables防火墙

    官方文档介绍地址: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Security_Gui ...

  9. Intel DAAL AI加速——神经网络

    # file: neural_net_dense_batch.py #================================================================= ...

  10. .NET 性能优化方法总结==转

    .NET 性能优化方法总结 目录 目录 1. C#语言方面... 4 1.1 垃圾回收... 4 1.1.1 避免不必要的对象创建... 4 1.1.2 不要使用空析构函数 ★... 4 1.1.3 ...