题目链接: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. PHP Problem with the SSL CA cert (path? access rights?)

    1.php使用curl模块报错问题 开发遇到问题,直接使用系统的curl命令正常,使用php的curl模块报错 错误:PHP Problem with the SSL CA cert (path? a ...

  2. ASP.NET Core 使用 AutoFac 注入 DbContext

    DI 1.0 -- 通过 RegisterInstance 注入 一开始,并不是很懂 AutoFac 的用法,又因为要使用特定的构造器和参数来初始化 DbContext,所以我想到的办法就是使用 Re ...

  3. 使用FIR.im发布自己的移动端APP

    一次很偶然的机会知道FIR.im,这家公司主要的产品就是帮助开发者方便便捷地发布iOS或者Android应用的.今天我就聊聊如何在FIR.im中发布自己的APP,然后让加入UUID的设备通过网页直接下 ...

  4. Python 和 R 数据分析/挖掘工具互查

    如果大家已经熟悉python和R的模块/包载入方式,那下面的表查找起来相对方便.python在下表中以模块.的方式引用,部分模块并非原生模块,请使用 pip install * 安装:同理,为了方便索 ...

  5. Upload java coed in Ubuntu(在Linux 16上,上传代码)

    指令如下:(按照如下指令顺序执行即可) 1.git status  (注释:可以查看哪些代码改动了) 2.git add .     (注意:不要漏掉add后面的" . ",将本地 ...

  6. 脚本改yum源

  7. PCB走线分析——直角、差分、蛇形线

    PCB直角走线的影响   布线(Layout)是PCB设计工程师最基本的工作技能之一.走线的好坏将直接影响到整个系统的性能,大多数高速的设计理论也要最终经过 Layout 得以实现并验证,由此可见,布 ...

  8. js的match()方法介绍

    定义和用法 match() 方法可在字符串内检索指定的值,或找到一个或多个正则表达式的匹配. 该方法类似 indexOf() 和 lastIndexOf(),但是它返回指定的值,而不是字符串的位置. ...

  9. php操作ini配置文件

    有些配置化的数据放到配置文件可以方便管理,比如数据库信息,路由信息,先建立配置文件,test.ini [database_setting] host=127.0.0.1 user=root passw ...

  10. centos7装机和初步运维

    1.装机-制作U盘启动盘 CentOS7是一个比较新的版本.在服务器领域用得比较多.因为前安装软件可能没有Ubuntu那样方便,所以桌面领域好像不是很多. https://www.centos.org ...