题目链接: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. 2016Unite Shanghai 总结

    有幸参加了Unite 2016 Shanghai unity开发者大会,这里做一些简单总结 一.日本Marza 分享 <The Gift> Marza用unity做渲染,加上一些自己的扩展 ...

  2. MX

    A mail exchanger record (MX record) is a type of resource record in the Domain Name System that spec ...

  3. pdf转word工具

    pdf转word工具及安装:http://blog.sina.com.cn/s/blog_6172011c0102vxir.html pdf去加密:http://www.downxia.com/dow ...

  4. Codeforces 235 E Number Challenge

    Discription Let's denote d(n) as the number of divisors of a positive integer n. You are given three ...

  5. sublime的tab和spaces空格切换的坑

    python是严格要求对齐或者叫缩进的: 使用sublime对python进行编程时,可以使用tab或者空格,但是不能混用.特别是从外面把代码拷贝进sublime的时候,更要注意是否一致. 简单介绍一 ...

  6. cocos2d-x3.0 PageView

    .h加入例如以下代码: void pageViewEvent(Ref *pSender, PageViewEventType type); .m layout = Layout::create(); ...

  7. 从头写一个Cucumber测试(二) Cucumber Test

    转载:https://yaowenjie.github.io/%E7%BC%96%E7%A8%8B%E7%9B%B8%E5%85%B3/cucumber-test-part-2 承接上文   前一篇博 ...

  8. python读取txt、csv和excel文件

    一.python读取txt文件:(思路:先打开文件,读取文件,最后用for循环输出内容) fp = open('test.txt','r') lines = fp.readlines() fp.clo ...

  9. 微信小程序制作商 业务流程

  10. NATSserver配置具体解释

    NATSserver配置具体解释 作者:chszs,未经博主同意不得转载. 经许可的转载需注明作者和博客主页:http://blog.csdn.net/chszs 虽然NATS能够无配置的执行,但也能 ...