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 ...
随机推荐
- 牛客网剑指offer【Python实现】——part1
斐波那契数列 大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项(从0开始,第0项为0,n<=39). 循环实现,时间复杂度n def Fibonacci(self, ...
- 1036. 跟奥巴马一起编程(15) Java版
美国总统奥巴马不仅呼吁所有人都学习编程,甚至以身作则编写代码,成为美国历史上首位编写计算机代码的总统.2014年底,为庆祝"计算机科学教育周"正式启动,奥巴马编写了很简单的计算机代 ...
- prometheus远程写参数优化
一.概述 prometheus可以通过远程存储来解决自身存储的瓶颈,所以其提供了远程存储接口,并可以通过过配置文件进行配置(prometheus.yml).一般情况下我们使用其默认的配置参数,但是为了 ...
- EntityFramework Core 3.x添加查询提示(NOLOCK)
前言 前几天看到有园友写了一篇关于添加NOLOCK查询提示的博文<https://www.cnblogs.com/weihanli/p/12623934.html>,这里呢,我将介绍另外一 ...
- TensorFlow报错module 'tensorflow' has no attribute 'xxx'解决办法
原因:TensorFlow2.0版本修改了许多函数名字 tf.sub()更改为tf.subtract() tf.mul()更改为tf.multiply() tf.types.float32更改为tf. ...
- RecyclerView 的简单使用
自从 Android 5.0 之后,google 推出了一个 RecyclerView 控件,他是 support-v7 包中的新组件,是一个强大的滑动组件,与经典的 ListView 相比,同样拥有 ...
- Pytest系列(4) - fixture的详细使用
如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 前面一篇讲了setup.te ...
- vuex知识要点梳理
该内容为个人总结,请勿喷. 欢迎各位大神前来指点.
- D - Expanding Rods POJ - 1905(二分)
D - Expanding Rods POJ - 1905 When a thin rod of length L is heated n degrees, it expands to a new l ...
- 老技术新谈,Java应用监控利器JMX(2)
各位坐稳扶好,我们要开车了.不过在开车之前,我们还是例行回顾一下上期分享的要点. 上期由于架不住来自于程序员内心的灵魂的拷问,于是我们潜心修炼,与 Java 应用监控利器 JMX 正式打了个照面. J ...