题目链接: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的更多相关文章
-
codeforces #round363 div2.C-Vacations (DP)
题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...
-
codeforces round367 div2.C (DP)
题目链接:http://codeforces.com/contest/706/problem/C #include<bits/stdc++.h> using namespace std; ...
-
codeforces 369 div2 C dp
http://codeforces.com/contest/711 C. Coloring Trees time limit per test 2 seconds memory limit per t ...
-
Codeforces#363 Div2
A题: 题意:给定一些数,给定一些往左走和往右走的操作,问是否能够相遇,如果相遇请求出相遇时间 分析:对于相邻两个数,如果大的往左,小的往右就能够相遇,否则不能相遇,在求出所有相遇当中的第一次相遇即可 ...
-
Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
-
Codeforces #180 div2 C Parity Game
// Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...
-
Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
-
Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
Problem Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...
-
Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)
Problem Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...
随机推荐
-
UiAutomator源代码分析之UiAutomatorBridge框架
上一篇文章<UIAutomator源代码分析之启动和执行>我们描写叙述了uitautomator从命令行执行到载入測试用例执行測试的整个流程.过程中我们也描写叙述了UiAutomatorB ...
-
UVA 12266 Stock prices --优先队列
优先队列. 做法:维护两个优先队列:quesell 和 quebuy, 一个是小值优先,一个是大值优先.每次push的时候,都取各自的Top元素,比较价格,如果卖的比卖的出价低,则成交,各自的要买 ...
-
6.struts登陆页面的演示
1.创建一个web project "Struts_1" 添加struts的jar包 --在项目文件右键->myeclipse->add struts... ...
-
Struts2流程分析与工具配置
1. 运行流程 请求 -- StrutsPrepareAndExecuteFilter 核心控制器 -– Interceptors 拦截器(实现代码功能 ) -– Action 的execuute - ...
-
jQuery 选择器 (一)
选择器 实例 选取 * $("*") 所有元素 #id $("#lastname") id="lastname" 的元素 .class $( ...
-
JS 中的this指向问题和call、apply、bind的区别
this的指向问题 一般情况下this对象指向调用函数的对象,全局环境中执行函数this对象指向window. function a(){ console.log(this); //输出函数a中的th ...
-
laravel中实现短信发送验证码
前段时间想实现一个短信验证码的功能,但是卡了很长时间. 首先我用的是阿里云的短信服务业务,其首次接入流程如下: 在阿里云上开通短信服务后需要做的: 1,申请签名 2,申请模板 3,创建Acces ...
-
spring data redis template GenericJackson2JsonRedisSerializer的使用
配置 <!-- redis template definition --> <bean id="myRedisTemplate" class="org. ...
-
Necklace (全排列 + 匈牙利)
#include<bits/stdc++.h> using namespace std; ][], Gra[][]; ]; ]; ]; bool dfs(int u, int vN) { ...
-
Javascript的一个怪现象
javascript有一个怪现象,就是减法也会导致小数位数问题,是一个麻烦的问题,比如. <html><script> var a=10,b=20.1; alert( a - ...