1324E - Sleeping Schedule
题目大意:一天有h个小时,一个人喜欢睡觉,一共睡n次,每次都睡h个小时,开始时间为0,间隔a[i]或a[i]-1个小时开始睡第i次觉,每天都有一个最好时间区间,问这n次觉,最多有多少次是在最好时间内睡的。
题解:定义状态dp[i][j]为第i次觉是在j时刻睡的,那么状态转移方程dp[i][j]=max(dp[i-1][(j-a[i]+h)%h],dp[i-1][(j-a[i]+1+h)%h]+
check(j)。
值得注意的是,不是每个状态都能够到达的,假设dp全部赋值为-1,当
dp[i-1][(j-a[i]+h)%h]==-1&&dp[i-1][(j-a[i]+1+h)%h]==-1时,状态dp[i][j]就无法到达......
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2E3+;
ll dp[N][N];
ll arr[N];
int main(){
ll n,h,l,r;
cin>>n>>h>>l>>r;
for(ll i=;i<=n;i++) cin>>arr[i];
memset(dp,-,sizeof dp);
ll c1=arr[]-;
ll c2=arr[];
dp[][c1]=(c1>=l&&c1<=r ? :);
dp[][c2]=(c2>=l&&c2<=r ? :);
ll ans=max(dp[][c1],dp[][c2]);
for(ll i=;i<=n;i++){
for(ll j=;j<h;j++){
ll c1=(j-arr[i]+h)%h;
ll c2=(j-arr[i]++h)%h;
if(dp[i-][c1]<&&dp[i-][c2]<) continue ;
dp[i][j]=max(dp[i][j],max(dp[i-][c1],dp[i-][c2])+(j>=l&&j<=r ? :));
}
}
for(ll i=;i<h;i++) ans=max(ans,dp[n][i]);
cout<<ans<<endl;
return ;
}
1324E - Sleeping Schedule的更多相关文章
- Codeforces 1324E Sleeping Schedule DP
题意 给你一个长度为\(n\)的数组\(a\)和3个数字\(h,l和r\).\(t\)初始为0,每次可以使\(t=(t+a_i) \% h\)或者\(t=(t+a_i-1)\%h\),如果这时\(t\ ...
- CF1324E Sleeping Schedule 题解
原题链接 简要题意: 每次可以将 \(a_i\) 减 \(1\) 或不变.求让 \(a_i\) 的前缀和 \(\% h\) 的值在 \([l,r]\) 区间中的最多的个数. E题是个水dp,也不怎样 ...
- Codeforces Round #627 (Div. 3) E - Sleeping Schedule(递推)
题意: 每天有 h 小时,有一序列 an,每次可以选择 ai 或 ai - 1 小时后睡觉,问从 0 次 0 时开始,最多在 l ~ r 时间段入睡多少次. 思路: 如果此时可达,计算此时可达的时间点 ...
- Educational Codeforces Round 21(A.暴力,B.前缀和,C.贪心)
A. Lucky Year time limit per test:1 second memory limit per test:256 megabytes input:standard input ...
- Average Sleep Time CodeForces - 808B (前缀和)
It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, on ...
- CF Educational Codeforces Round 21
A. Lucky Year time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- [LeetCode] Course Schedule II 课程清单之二
There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prer ...
- [LeetCode] Course Schedule 课程清单
There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prer ...
- POJ 1325 Machine Schedule——S.B.S.
Machine Schedule Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13731 Accepted: 5873 ...
随机推荐
- hdu1226超级密码 bfs
题目链接:http://icpc.njust.edu.cn/Problem/Hdu/1226/ 题目大意是:寻找一个五百位之内的C进制密码,该密码是N的正整数倍,而且只能用给定的数构成密码,求这样的密 ...
- 进制-Adding Two Negabinary Numbers
2020-02-20 14:52:41 问题描述: 问题求解: 最开始的想法是将两个数字先转化成自然数在求和,最后转化回去,但是实际上这种方案是不可取的,主要的问题就是会爆掉. 那么就得按位进行运算了 ...
- 李宏毅老师机器学习课程笔记_ML Lecture 0-1: Introduction of Machine Learning
引言: 最近开始学习"机器学习",早就听说祖国宝岛的李宏毅老师的大名,一直没有时间看他的系列课程.今天听了一课,感觉非常棒,通俗易懂,而又能够抓住重点,中间还能加上一些很有趣的例子 ...
- Vue2.0 -- 钩子函数/ 过度属性/常用指令/以及Vue-resoure发送请求
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Swagger2 初始用
1.结合Spring-Boot 引入 pom 依赖 <dependency> <groupId>io.springfox</groupId> <artifa ...
- Springboot + Freemarker(一)
Maven pom文件配置 <parent> <groupId>org.springframework.boot</groupId> <artifactId& ...
- WScript.Shell 与 Shell.Application 的不同
本文主要对比,VBScript 中 CreateObject("WScript.Shell") 和 CreateObject("Shell.Application&quo ...
- Pycharm 文件模板配置
Pycharm 模板配置 #!/usr/bin/python # -*- coding: UTF-8 -*- # Author:${USER} 作者 # FileName:${NAME} 文件名称 # ...
- ElasticSearch、IK分词器、Head Master安装-----Windows
一.下载 地址:https://www.elastic.co/cn/downloads/elasticsearch 历史版本:找到下面这句话 然后双击 Not the version you're l ...
- Spring Boot 整合视图层技术,application全局配置文件
目录 Spring Boot 整合视图层技术 Spring Boot 整合jsp Spring Boot 整合freemarker Spring Boot 整合视图层技术 Spring Boot 整合 ...