首页 > 其他分享 >CF1608F MEX counting

CF1608F MEX counting

时间:2023-05-11 15:15:03浏览次数:31  
标签:转移 le limits MEX CF1608F sum mex counting operatorname

题意

给定 \(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}\) 的方案数。写一下转移:

\[f_{i, j, k} = f_{i-1, j, k-1} + (j-1)f_{i-1,j,k} + \sum\limits_{t=0}^{j-1}\sum\limits_{p}\binom{k+p}{p}{p\brace j-t-1}(j-t-1)!f_{i-1,t,k+p} \]

发现状态数 \(n^2k\),转移怎么也不能做到 \(\mathrm O(1)\)。于是我就极限降智。

怎么优化呢?注意到比较恶心的是 \(p\),主要是我们虽然知道转移从 \(t\) 到 \(j\) 的过程中一定要用未决策的数去填满 \(t-j-1\) 个位置,但是不知道具体有几个数,怎么把这些数放进去。然后你发现与这边巨大多的式子形成鲜明对比的是你在把数延迟决策的时候机会什么都不干。于是你考虑改一改状态:\(g_{i,j,k}\) 表示前 \(i\) 个数,\(\operatorname{mex}\) 为 \(j\),大于当前 \(\operatorname{mex}\) 的数分为 \(k\) 类的方案数。于是转移就是:

\[g_{i, j, k} = (j + k)g_{i-1, j, k} + g_{i-1,j,k-1} + \sum\limits_{t=0}^{j-1}\binom{k + j - t - 1}{j - t - 1}(j - t - 1)!g_{i-1,t,k+j-t-1} \]

这个转移随便拆一下做个前缀和就 \(\mathrm O(1)\) 了。

标签:转移,le,limits,MEX,CF1608F,sum,mex,counting,operatorname
From: https://www.cnblogs.com/kyeecccccc/p/17391066.html

相关文章

  • LightOJ - 1058 Parallelogram Counting (数学几何&技巧)给n个点求组成平行四边形个数
    LightOJ-1058ParallelogramCountingTimeLimit: 2000MSMemoryLimit: 32768KB64bitIOFormat: %lld&%lluSubmit StatusDescriptionThereare n distinctpointsintheplane,givenbytheirintegercoordinates.Findthenumberofparallelogramswhosever......
  • C. Ehab and Path-etic MEXs
    C.EhabandPath-eticMEXs对于成链的情况,\(\text{MEX}=n-1\)一般的,一定有一条路径包含0和1,则可以确定\(\text{MEX}\geq2\),观察发现,对于度数\(\geq3\)的点,我们在他的三条边赋值为0,1,2使得其他路径的边有:0,1,...0,2,...1,2,...即一条路径上的边不能同时有0,1,......
  • java.security.NoSuchAlgorithmException: Cannot find any provider supporting AES/
    Java使用AES/CBC/PKCS7Padding加解密时会报错,因为原生JDK不支持。1.在jdk中的jre\lib\security修改java.security文件,替换security.provider.7=org.bouncycastle.jce.provider.BouncyCastleProvider2./jdk/jre/lib/ext下添加jar包bcprov-jdk15on-1.58.jar ......
  • Codeforces Gym 103439D - LIS Counting(猜结论+状压)
    一道需要一些猜结论技巧的中档题。首先突破口在于排列长度恰好等于不是额外输入的某个数\(k\)而是LDS与LIS的乘积,这显然启示我们去找一些性质。根据dilworth定理,最长反链等于最小链覆盖,故LIS的长度,就是最少需要的递减数列的个数使得每个元素被覆盖至少一次,而每个递减数......
  • PAT Advanced 1004. Counting Leaves
    PATAdvanced1004.CountingLeaves1.ProblemDescription:Afamilyhierarchyisusuallypresentedbyapedigreetree.Yourjobistocountthosefamilymemberswhohavenochild.2.InputSpecification:Eachinputfilecontainsonetestcase.Eachcases......
  • 2017ACM/ICPC广西邀请赛-重现赛(感谢广西大学)C - Counting Stars 暴力三元环
    LittleAisanastronomylover,andhehasfoundthattheskywassobeautiful!Soheiscountingstarsnow!Therearenstarsinthesky,andlittleAhasconnectedthembymnon-directionaledges.Itisguranteedthatnoedgesconnectonestarwithi......
  • Hydro Tools:System.Runtime.InteropServices.COMException (0x80004005)
     在使用hydrotools的时候报了这个错误 然后看到一个solution 这个设置一下 rasterworkspace要选择它默认的图层layer不是gdb,只有vectorworkspace才是gdb ......
  • Counting Rectangles UVA - 10574
    给出n个点。问选出4个点作为定点,能够组成多少个平行与坐标轴的矩形。 点按照x排序 n^2挑选出垂直x轴的线段,按照y1排序  #include<iostream>#include<cstring>#include<algorithm>#include<vector>usingnamespacestd;constintN=1e5;structT{ intx......
  • Counting
    CountingTypeRepetitionAllowed?Formular-permutationsNo$P_n^k=r!{n\choosek}$r-combinationsNo\(C_n^k={n\chooser}\)r-permutationsYes\(n^k\)r-combinationsYes$C_{n+k-1}^k={n+k-1\choosek}$r-combinationswit......
  • 菜鸟记录:c语言实现PAT甲级1004--Counting Leaves
    好消息:与上题的Emergency是同样的方法。坏消息:又错了&&c++真的比c方便太多太多。Afamilyhierarchyisusuallypresentedbyapedigreetree.Yourjobistocountthosefamilymemberswhohavenochild.InputSpecification:Eachinputfilecontainsonetest......