题目链接:C. Vacations

题意:现在有n天的假期,对于第i天有四种情况:

0   gym没开,contest没开

1   gym没开,contest开了

2   gym开了,contest没开

3       gym开了,contest开了

所有题主每天可能就有三种选择,rest,do sport,do contest。题主拒绝连续两天做同样的事情。现在请你安排他的假期,使得题主休息的天数最少。

思路:tag:dp

n=100的dp和暴力有什么区别... ...

第i天的三种选择得到的最少休息天数,只需要知道第i-1天的对应(活动不重复)选择得到的最少休息天数。

感觉这种dp初始化比状态转移方程还要麻烦~~~

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<iostream>
#include<vector>
#define maxn 210
#define inf 9999999
using namespace std; ///不能连续做两天一样的活动 安排使其休息最少的天数 问最少休息的天数 int val[maxn];
int dp[maxn][5]; /// 0 rest 1 sport 2 contest int main() {
// freopen("in.cpp", "r", stdin);
int n;
while(~scanf("%d", &n)) {
for (int i=1; i<=n; ++i) {
scanf("%d", &val[i]);
} for (int i=1; i<=n; ++i) {
dp[i][0] = inf;
dp[i][1] = inf;
dp[i][2] = inf;
} dp[1][0] = 1;
if (val[1] == 2 || val[1] == 3) {
dp[1][1] = 0;
}
if (val[1] == 1 || val[1] == 3) {
dp[1][2] = 0;
} for (int i=2; i<=n; ++i) {
dp[i][0] = min(dp[i-1][0], min(dp[i-1][1], dp[i-1][2]))+1;
if (val[i] == 2 || val[i] == 3) {
dp[i][1] = min(dp[i-1][0], dp[i-1][2]);
}
if (val[i] == 3 || val[i] == 1) {
dp[i][2] = min(dp[i-1][1], dp[i-1][0]);
}
} int ans = min(dp[n][0], min(dp[n][1], dp[n][2]));
printf("%d\n", ans);
}
return 0;
}

CodeForces #363 div2 Vacations DP的更多相关文章

  1. codeforces #round363 div2.C-Vacations (DP)

    题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...

  2. codeforces round367 div2.C (DP)

    题目链接:http://codeforces.com/contest/706/problem/C #include<bits/stdc++.h> using namespace std; ...

  3. codeforces 369 div2 C dp

    http://codeforces.com/contest/711 C. Coloring Trees time limit per test 2 seconds memory limit per t ...

  4. Codeforces#363 Div2

    A题: 题意:给定一些数,给定一些往左走和往右走的操作,问是否能够相遇,如果相遇请求出相遇时间 分析:对于相邻两个数,如果大的往左,小的往右就能够相遇,否则不能相遇,在求出所有相遇当中的第一次相遇即可 ...

  5. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

  6. Codeforces #180 div2 C Parity Game

    // Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...

  7. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  8. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  9. Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)

    Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...

随机推荐

  1. 打气筒的Api

    1.获取打气筒的第一种方法 view=View.inflate(getApplicationContext(),R.layout.tv,null); 2.获取打气筒的第二种方法 view=Layout ...

  2. nginx安装方式

    1.首先安装pcre库 获取pcre到一个目录 wget http://ftp.exim.llorien.org/pcre/pcre-8.21.tar.gz 解压缩pcre包 tar -zxvf pc ...

  3. CentOS 7 程序自启动的问题

    Mysql具体的安装方法见http://www.cnblogs.com/yoyotl/p/5752437.html 但是关于自启动部分需要多一些说明. 一.问题现象: 系统重启后,发现mysqld服务 ...

  4. 微信小程序-登陆、支付、模板消息

    wx.login(OBJECT) 调用接口获取登录凭证(code)进而换取用户登录态信息,包括用户的唯一标识(openid) 及本次登录的 会话密钥(session_key).用户数据的加解密通讯需要 ...

  5. C#的四种Timer介绍

    一.Timer的几个类别 1.System.Threading.Timer 2.System.Timers.Timer 3.System.Windows.Forms.Timer 4.System.Wi ...

  6. test lab ~ triangle test by using junit and coverage

    first set up a new folder as your test class place, and then let your package in test class folder b ...

  7. Linux就该这么学

    第三章:Vim编辑器与Shell脚本 Vim文本编辑器 在Linux系统中配置应用服务,实际上就是在修改它的配置文件. 在热门的Linux操作系统中都会默认安装一款超好用的文本编辑器--"v ...

  8. hadoop修改MR的提交的代码程序的副本数

    hadoop修改MR的提交的代码程序的副本数 Under-Replicated Blocks的数量很多,有7万多个.hadoop fsck -blocks 检查发现有很多replica missing ...

  9. C语言习题(结构)

    实际应用中经常会用到二维平面上的点,点的操作包括设置点的位置( pointT setPoint(double x , double y ) ),显示第n个点的位置( void showPoint(po ...

  10. log4j PatternLayout 输出解析

    以下是PatternLayout.class源码的文档介绍: A flexible layout configurable with pattern string. This code is know ...