CF1608F MEX counting
题意
给定 \(n, k\) 和序列 \(b_{1\dots n}\),计数序列 \(a_{1\dots n}\) 使得 \(\forall i \in [1, n], \operatorname{mex}\limits_{j=1}^i\{a_j\}\in [b_i - k, b_i + k]\)。
数据范围:\(1\le b_i \le n \le 2000, 0\le k\le 50\)。
题解
永远做不出简单题。我是弱智。
考虑递推过程中维护 \(\operatorname{mex}\) 的变化,那么需要在每个 \(i\) 处决策 \(\operatorname{mex}\) 增加多少,那么考虑在某一个数变成小于 \(\operatorname{mex}\) 的位置再去决策它的具体值。记 \(f_{i, j, k}\) 表示前 \(i\) 个数,\(\operatorname{mex}\) 为 \(j\),有 \(k\) 个数大于当前的 \(\operatorname{mex}\) 的方案数。写一下转移:
\]
发现状态数 \(n^2k\),转移怎么也不能做到 \(\mathrm O(1)\)。于是我就极限降智。
怎么优化呢?注意到比较恶心的是 \(p\),主要是我们虽然知道转移从 \(t\) 到 \(j\) 的过程中一定要用未决策的数去填满 \(t-j-1\) 个位置,但是不知道具体有几个数,怎么把这些数放进去。然后你发现与这边巨大多的式子形成鲜明对比的是你在把数延迟决策的时候机会什么都不干。于是你考虑改一改状态:\(g_{i,j,k}\) 表示前 \(i\) 个数,\(\operatorname{mex}\) 为 \(j\),大于当前 \(\operatorname{mex}\) 的数分为 \(k\) 类的方案数。于是转移就是:
\]
这个转移随便拆一下做个前缀和就 \(\mathrm O(1)\) 了。
CF1608F MEX counting的更多相关文章
- 萌新笔记——Cardinality Estimation算法学习(二)(Linear Counting算法、最大似然估计(MLE))
在上篇,我了解了基数的基本概念,现在进入Linear Counting算法的学习. 理解颇浅,还请大神指点! http://blog.codinglabs.org/articles/algorithm ...
- POJ_2386 Lake Counting (dfs 错了一个负号找了一上午)
来之不易的2017第一发ac http://poj.org/problem?id=2386 Lake Counting Time Limit: 1000MS Memory Limit: 65536 ...
- ZOJ3944 People Counting ZOJ3939 The Lucky Week (模拟)
ZOJ3944 People Counting ZOJ3939 The Lucky Week 1.PeopleConting 题意:照片上有很多个人,用矩阵里的字符表示.一个人如下: .O. /|\ ...
- find out the neighbouring max D_value by counting sort in stack
#include <stdio.h> #include <malloc.h> #define MAX_STACK 10 ; // define the node of stac ...
- 1004. Counting Leaves (30)
1004. Counting Leaves (30) A family hierarchy is usually presented by a pedigree tree. Your job is ...
- 6.Counting Point Mutations
Problem Figure 2. The Hamming distance between these two strings is 7. Mismatched symbols are colore ...
- 1.Counting DNA Nucleotides
Problem A string is simply an ordered collection of symbols selected from some alphabet and formed i ...
- Codeforces Round #381 (Div. 2)C. Alyona and mex(思维)
C. Alyona and mex Problem Description: Alyona's mother wants to present an array of n non-negative i ...
- Codeforces 740C. Alyona and mex 思路模拟
C. Alyona and mex time limit per test: 2 seconds memory limit per test: 256 megabytes input: standar ...
- uva 11401 Triangle Counting
// uva 11401 Triangle Counting // // 题目大意: // // 求n范围内,任意选三个不同的数,能组成三角形的个数 // // 解题方法: // // 我们设三角巷的 ...
随机推荐
- 关于Cookie要懂的知识
☞演示 什么是Cookie? http是一个无状态协议,它不对之前发生过的请求和响应的状态进行管理.这样就可能导致,我们登陆一个网站后,每次跳转新页面,之前的登陆状态都不能被记住,要重新登陆等问题. ...
- [数据库/MYSQL]#解决缺陷#设置Unique索引时:"[Err] 1071 - Specified key was too long; max key length is 767 bytes"
1 问题复现 原表结构: CREATE TABLE `XX_TEMPERATURE` ( `FLOW_ID` int(11) NOT NULL COMMENT '独立的数据表或FTP唯一标识', -- ...
- postgresSQL Extended Query执行过程和sharding-proxy的处理
pg Extended Query PostgreSQL: Documentation: 15: 55.2. Message Flow 多个阶段,可复用 Parse → DESCRIBE statem ...
- day115:MoFang:种植园我的背包&种植园道具购买
目录 1.我的背包 2.道具购买 1.我的背包 1.在种植园点击背包按钮打开我的背包 在种植园打开背包,orchard.html,代码: <!DOCTYPE html> <html& ...
- group_concat_max_len设置过小致group_concat()排列不全
问题描述:group_concat_max_len默认值1024导致group_concat函数排列显示不足 group_concat_max_len长度显示跟group_concat排列长度息息相关 ...
- fzy&czn生日赛t1 CZN
fzy&czn生日赛t1 CZN 膜拜hybb首杀 目录 fzy&czn生日赛t1 CZN 题目背景 题目描述 分析 my code wnag's code 题目 题目背景 有一天,c ...
- vue2中使用composition-api
vue2中使用composition-api https://juejin.cn/post/6874927606820274184 vue3.0 watch 函数 https://www.jiansh ...
- Spring Security 报:Encoded password does not look like BCrypt
SpringBoot 集成 Security 时,报 Encoded password does not look like BCrypt 原因:SecurityConfig 必须 Bean 的形式实 ...
- Prism Sample 15-FilteringEvents
例14演示了怎样事件聚合器怎样发布与接收信息. 例15增加了一个事件的过滤功能,即设定一个条件,符合的才接收. _ea.GetEvent<MessageSentEvent>().Subsc ...
- 扯什么kafka顺序消费,然后呢?古尔丹,代价是什么
著名面试八股文之kafka为什么读写效率高,写的答案之一是partition顺序写,因而能保证分区内的不连续的有序性. 这里的重点是有序追加到磁盘,而不是严格意义上的完全有序性. 几年前参加了一大数据 ...