CodeForces-1324E-Sleeping-Schedule】的更多相关文章

题意 给你一个长度为\(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个小时,一个人喜欢睡觉,一共睡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]…
题意: 每天有 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_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_…
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…
A. Alena's Schedule Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586/problem/A Description Alena has successfully passed the entrance exams to the university and is now looking forward to start studying. One two-hour less…
题目链接:http://codeforces.com/contest/1138/problem/D 题目大意:给你两个字符串s1和s2(只包含0和1),对于s1中,你可以调换任意两个字符的位置.问你最多能在s1中构造出几个s2(可重叠). 具体思路:首先找到字符串s2的最小循环节,比如说1101,我们找到的最小循环节就是101,这样的话,我们每次在后面加上101就能构造出一个新的1101了,最小循环节是最小的代价. AC代码: #include<bits/stdc++.h> using nam…
Codeforces 1137 B 题意:给两个串\(S\).\(T\),问将\(S\)中字符任意调换后出现\(T\)次数最多的方案. 思路:我们首先考虑怎么样放\(T\)才是最优的.我们直观上考虑前后两个\(T\)的出现肯定要重叠一定的面积,那么我们考虑\(T\)的最长的与前缀相同的后缀\(T'\),我们最终的答案希望是这样的:\(TT...TT'\). 所以我们枚举\(T'\)出现的次数,看\(S\)中字符是不是够即可.\(T'\)的长度需要用\(Z\_function\)或KMP来求.我考…