Codeforces Round #363 (Div. 2) C. Vacations —— DP
题目链接: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的更多相关文章
- 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 ...
- 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 ...
- Codeforces Round 363 Div. 1 (A,B,C,D,E,F)
Codeforces Round 363 Div. 1 题目链接:## 点击打开链接 A. Vacations (1s, 256MB) 题目大意:给定连续 \(n\) 天,每天为如下四种状态之一: 不 ...
- 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 ...
- CodeForces 698A - Vacations (Codeforces Round #363 (Div. 2))
要么去体育馆,要么去比赛,要么闲在家里 给出每一天体育馆和比赛的有无情况,要求连续两天不能去同一个地方 问最少闲几天 DP方程很容易看出 dp(第i天能去的地方) = min(dp(第i-1天的三种情 ...
- Codeforces Round #363 (Div. 2)
A题 http://codeforces.com/problemset/problem/699/A 非常的水,两个相向而行,且间距最小的点,搜一遍就是答案了. #include <cstdio& ...
- Codeforces Round #363 Div.2[111110]
好久没做手生了,不然前四道都是能A的,当然,正常发挥也是菜. A:Launch of Collider 题意:20万个点排在一条直线上,其坐标均为偶数.从某一时刻开始向左或向右运动,速度为每秒1个单位 ...
- Codeforces Round #131 (Div. 1) B. Numbers dp
题目链接: http://codeforces.com/problemset/problem/213/B B. Numbers time limit per test 2 secondsmemory ...
- Codeforces Round #131 (Div. 2) B. Hometask dp
题目链接: http://codeforces.com/problemset/problem/214/B Hometask time limit per test:2 secondsmemory li ...
随机推荐
- 思科CCIE全新升级,SDN/SD-WAN成重头戏!
CCIE,全称Cisco Certified Internetwork Expert,是美国Cisco公司于1993年开始推出的专家级认证考试.被全球公认为IT业最权威的认证,是全球Internetw ...
- codeforces A. Wrong Subtraction
A. Wrong Subtraction time limit per test 1 second memory limit per test 256 megabytes input standard ...
- java保留n位小数
double x = 123456789.987654312; String.format("%.nf", x) n为保留的小数位,x必须为double类型. 例如保留3位小数 S ...
- IntelliJ IDEA常用统一设置2-Inspections检查设置(Linux/Mac/Windows)
Inspections检查设置功能,能检查一些普通问题,比如代码风格等等.当然,这个虽然没有CheckStyle这些插件专业,但也是另一种选择. 官方参考:https://www.jetbrains. ...
- pv,uv
1.PV PV(page view),即页面浏览量:用户每1次对网站中的每个网页访问均被记录1次.用户对同一页面的多次访问,访问量累计. 2.什么是UV uv(unique visitor),指访问某 ...
- FireDAC 出现Variable length column[*] overflow. Value length - [80], column maximum length
FireDAC 出现Variable length column[*] overflow. Value length - [80], column maximum length FireDAC的 TF ...
- jquery 查找子元素的几种方法
<div class="tm-clear tb-hidden tm_brandAttr" id="J_BrandAttr" style="dis ...
- 从SDCard获取的图片按分辨率处理的方法
前段时间公司开发的Launcher要做主题切换的功能,但切换主题时须要从sdcard中获取要切换的图片资源,拿到后图片的大小不正常. 后来查找原因是:系统对不同分辨率拿到的图片资源会自己主动的做转化, ...
- ajax加载时的进度条
运行效果如下图,pc和移动都可以展示,调用方法很简单,开始调用:loading.baosight.showPageLoadingMsg(false),false代表不现实加载说明,true展示加载说明 ...
- Vue 字面量语法 vs 动态语法
初学者常犯的一个错误是使用字面量语法传递数值: <!-- 传递了一个字符串 "1" --> <comp some-prop="1">&l ...