题目链接: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. Pro Git 第一章 起步 读书笔记

    Pro Git 笔记 第1章 起步 1.文件的三种状态. 已提交:文件已经保存在本地数据库中了.(commit) 已修改:修改了某个文件,但还没有提交保存.(vim) 已暂存:已经把已修改的文件放在下 ...

  2. Apache2.4权限配置(原创帖-转载请注明出处)

    ==================说在前面的话================= 1:这次实验使用的php项目是Discuz,Discuz的安装请参照:http://www.cnblogs.com/ ...

  3. springmvc使用freemarker

    首先需要添加freemarker.jar到项目,如果项目中有spring或者spirngmvc,需要整合,首先配置freemarkerConfig,代码结构如下 <!-- 设置freeMarke ...

  4. SunRay4(新蕾4) 定时自动关机方案, Linux后台自动任务crontab实践

    目录: 需求和思路分析 具体实现步骤 理解Crontab Crontab具体参数详细说明 最近碰到一个想要实现定时自动关机的功能,关机的指令无非就是: shutdown -h time 调用openw ...

  5. MFC动态创建菜单

    http://blog.csdn.net/csdnzhwk/article/details/47395639

  6. vpsmate安装

    安装需求 操作系统:CentOS/Redhat 5.4 或 5.4 以上版本,32位或64位均可,推荐使用 CentOS 6.2 64位. 内存大小:运行时占用约 20MB 左右的服务器内存. 请使用 ...

  7. 微信小程序-表单组件

    button 按钮 注:button-hover 默认为{background-color: rgba(0, 0, 0, 0.1); opacity: 0.7;} 示例代码: /** wxss **/ ...

  8. c++左值和右值

    c++编程中如果出现把一个函数的返回值.强行转化后的对象 作为函数的参数传进去时,编译器会报错的情况.这时候就该注意了,你需要把该函数的参数类型前加上const修饰. 原因在于c++的左值和右值有所区 ...

  9. Analyzer报表里显示的 * 星号、红叉、#井号的意义

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  10. php : 基础(5)

    函数 函数的定义: 形式: function 函数名 ( [$形参1] [,$形参2] [,.... ] ){ //函数体...... } 说明: 定义时使用的形参,其实就是一个变量--只能在该函数内 ...