题目链接:http://codeforces.com/contest/699/problem/C

题解:

1.可知每天有三个状态:1.contest ,2.gym,3.rest。

2.所以设dp[i][j](i:1~n,j:1~3)为第i天进行j活动的最小休息天数。

3.状态转移:

contest:如果当天可以进行,从上一天的gym和rest中转移过来,取最小值。否者置为无限大INF。

gym:如果当天可以进行,从上一天的contest和rest中转移过来, 取最小值。否则置为无限大INF。

rest:每一天都可以进行。 从上一天的contest、gym和rest中转移过来, 取最小值。

4.最后取第n天的三个状态的最小值即为答案。

代码如下:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#include <algorithm>
using namespace std;
#define pb push_back
#define mp make_pair
#define ms(a, b) memset((a), (b), sizeof(a))
#define eps 0.0000001
typedef long long LL;
const int INF = 2e9;
const LL LNF = 9e18;
const int mod = 1e9+7;
const int maxn = 200000+10; int n;
int a[1005], dp[1005][3]; int main()
{
scanf("%d",&n);
for(int i = 1; i<=n; i++)
scanf("%d",&a[i]); for(int i = 1; i<=n; i++)//初始化为无限大, 表示当天不能进行此项活动。
for(int j = 1; j<=3; j++)
dp[i][j] = INF; dp[0][1] = dp[0][2] = dp[0][3] = 0;//第0天时,三种状态都为0。
for(int i = 1; i<=n; i++)
{
if(a[i]%2) dp[i][1] = min( dp[i-1][2], dp[i-1][3] ); //contest
if(a[i]/2) dp[i][2] = min( dp[i-1][1], dp[i-1][3] ); //gym
dp[i][3] = min( dp[i-1][1], min(dp[i-1][2], dp[i-1][3]) ) + 1;
} int ans = min( min(dp[n][1], dp[n][2]), dp[n][3] );
printf("%d\n",ans); return 0;
}

Codeforces Round #363 (Div. 2) C. Vacations —— DP的更多相关文章

  1. 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 ...

  2. 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 ...

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

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

  4. Codeforces Round #363 (Div. 2) C dp或贪心 两种方法

    Description Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasy ...

  5. CodeForces 698A - Vacations (Codeforces Round #363 (Div. 2))

    要么去体育馆,要么去比赛,要么闲在家里 给出每一天体育馆和比赛的有无情况,要求连续两天不能去同一个地方 问最少闲几天 DP方程很容易看出 dp(第i天能去的地方) = min(dp(第i-1天的三种情 ...

  6. Codeforces Round #363 (Div. 2)

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

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

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

  8. Codeforces Round #131 (Div. 1) B. Numbers dp

    题目链接: http://codeforces.com/problemset/problem/213/B B. Numbers time limit per test 2 secondsmemory ...

  9. Codeforces Round #131 (Div. 2) B. Hometask dp

    题目链接: http://codeforces.com/problemset/problem/214/B Hometask time limit per test:2 secondsmemory li ...

随机推荐

  1. 3.eclipse中 maven打包web工程几种方式

    1.右键项目-export 选择war file导出即可 2.第二种:右键项目-RUN AS -maven build..goals填入:clean package 第三种方式:右键项目.选择Debu ...

  2. Spring Boot中实现异步调用之@Async

    一.什么是异步调用 “异步调用”对应的是“同步调用”,同步调用指程序按照定义顺序依次执行,每一行程序都必须等待上一行程序执行完成之后才能执行:异步调用指程序在顺序执行时,不等待异步调用 的语句返回结果 ...

  3. Could not change executable permissions on the application

    I could solve it erasing an application that I had previously uploaded using the same Bundle Identif ...

  4. 【hibernate】Hibernate中get()和load()的区别

    Hibernate中根据Id单条查询获取对象的方式有两种,分别是get()和load(),来看一下这两种方式的区别. 1. get() 使用get()来根据ID进行单条查询: 1 User user= ...

  5. 漫谈深度学习时代点击率预估技术进展 &&深度学习在推荐系统上的发展

    转载:https://www.infoq.cn/article/XA055tpFrprUy*0UBdCb https://www.zhihu.com/question/20830906/answer/ ...

  6. TI C66x DSP 四种内存保护问题 -之- CPU訪问corePac内部资源时的内存保护问题

    CPU訪问corePac内部资源(L1.L2)时的内存保护(通过设置内存的訪问权限实现)等问题请參考以下两个blog.已经叙述的非常具体. "TI C66x DSP 系统events及其应用 ...

  7. Mybatis分页插件-PageHelper的使用

    转载:http://blog.csdn.net/u012728960/article/details/50791343 Mybatis分页插件-PageHelper的使用 怎样配置mybatis这里就 ...

  8. LoadRunner多负载产生器

    Executive Summary : The following explains why it is necessary to have about 6 load generators when ...

  9. openssl之BIO系列之12---文件描写叙述符(fd)类型BIO

    文件描写叙述符(fd)类型BIO ---依据openssl doc\crypto\bio_s_fd.pod翻译和自己的理解写成 (作者:DragonKing Mailwzhah@263.net 公布于 ...

  10. vs2012编译ffmpeg

    从官方网站down下来的ffmpeg没有pdb文件不方便调试,为此使用VS2012编译ffmpeg. 编译步骤: 一.安装MinGW,具体的安装方法上一篇文章已经有介绍这里不在赘述. 二.下载文件并放 ...