CF1324E Sleeping Schedule 题解】的更多相关文章

原题链接 简要题意: 每次可以将 \(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_…
Machine Schedule Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14479   Accepted: 6172 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…
题目大意:一天有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代…
题意: 每天有 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>>…
Course Schedule题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/course-schedule/description/ Description 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 ha…
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…
拓扑排序基础 拓扑排序用于解决有向无环图(DAG,Directed Acyclic Graph)按依赖关系排线性序列问题,直白地说解决这样的问题:有一组数据,其中一些数据依赖其他,问能否按依赖关系排序(被依赖的排在前面),或给出排序结果. 最常用解决拓扑排序问题的方法是Kahn算法,步骤可以概括为: . 根据依赖关系,构建邻接矩阵或邻接表.入度数组 . 取入度为0的数据(即不依赖其他数据的数据),根据邻接矩阵/邻接表依次减小依赖其的数据的入度 . 判断减小后是否有新的入度为0的数据,继续进行第2…
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…