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]…
题意 给你一个长度为\(n\)的数组\(a\)和3个数字\(h,l和r\).\(t\)初始为0,每次可以使\(t=(t+a_i) \% h\)或者\(t=(t+a_i-1)\%h\),如果这时\(t\in\left[l,r\right]\)就将\(ans\)加1.求\(ans\)的最大值. 解题思路 这场比赛的题感觉偏简单了. 这是一道显而易见的DP题.\(dp_{i,j,k}\)表示枚举到\(a_i\),当前\(t=j\),是否-1时的\(ans\)的最大值,很容易就能推导出转移公式. AC代…
原题链接 简要题意: 每次可以将 \(a_i\) 减 \(1\) 或不变.求让 \(a_i\) 的前缀和 \(\% h\) 的值在 \([l,r]\) 区间中的最多的个数. E题是个水dp,也不怎样 用 \(f_{i,j}\) 表示前 \(i\) 个数中,\(\bigg ( \sum_{k=1}^{i} a_k \bigg ) \% h = j\) 的最大答案. 显然,我们从第 \(i\) 个数入手.(下标出现负数的,在代码中均处理:转移方程中保留) 如果不选,那么 \(f_{i,j} = f_…
题意: 每天有 h 小时,有一序列 an,每次可以选择 ai 或 ai - 1 小时后睡觉,问从 0 次 0 时开始,最多在 l ~ r 时间段入睡多少次. 思路: 如果此时可达,计算此时可达的时间点及其是否位于 l ~ r 区间. #include <bits/stdc++.h> using namespace std; const int M=2200; int dp[M][M]; int main() { int n,h,l,r;cin>>n>>h>>…
A. Lucky Year time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lu…
It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts k days! When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically,…
A. Lucky Year time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lu…
There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pair: [0,1] Given the total number of courses and a l…
There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pair: [0,1] Given the total number of courses and a l…
Machine Schedule Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13731   Accepted: 5873 Description As we all know, machine scheduling is a very classical problem in computer science and has been studied for a very long history. Scheduli…