正文
增加 85 行删除 22 行
1234567891011121314151617181944 行未改动646566676869707172737475767725 行未改动103104105106107## 数学公式### 二项式定理:$(a+b)^n=\sum\limits_{i=0}^n\dbinom{n}{i} a^i b^{n-i}$#### 拓展:$\sum\limits_{i=0}^n\dbinom{n}{i}=(1+1)^n$$\sum\limits_{i=0}^n(-1)^i\dbinom{n}{i}=[n=0]$### 二项式反演:若$g_n=\sum\limits_{i=0}^n\dbinom{n}{i}f_i$则有$f_n=\sum\limits_{i=0}^n(-1)^{n-i}\dbinom{n}{i}g_i$### 容斥原理:$|\bigcup\limits_{i=1}^nS_i|=\sum\limits_{i=1}^n(-1)^{i-1}\sum\limits_{a_i<a_i+1}|\bigcup\limits_{i=1}^iS_{a_i}|$## 小技巧1.推得不充分必要条件时,可以使用hash转为充要条件,例题[P8819 [CSP-S 2022] 星战](https://www.luogu.com.cn/problem/P8819)44 行未改动24.像买东西再卖掉这种贪心问题时,若感到不好贪,考虑将购买的每个物品的价值、数量同时放入单调队列贪心。25.[排列笑传之逆序列字典序不变而好处理](https://www.luogu.com.cn/problem/AT_agc001_f)26.[背包笑传之数量多猜种类少,多重背包开始洲际](https://www.luogu.com.cn/problem/CF1481F)27.[前缀和肘飞多重背包计数](https://www.luogu.com.cn/problem/AT_arc104_d)28.第二类斯特林数模板[P3904 三只小猪](https://www.luogu.com.cn/problem/P3904)29.二项式定理应用例题[P10185 [YDOI R1] Necklace](https://www.luogu.com.cn/problem/P10185)30.[cdq洲飞dp](https://www.luogu.com.cn/problem/P2487)31.[cdq和斜率优化一起洲际dp](https://www.luogu.com.cn/problem/P2497)32.算方案数时若总方案数不好算,考虑什么时候会导致方案数变化,计算这个突变点,例题[P7322 「PMOI-4」排列变换](https://www.luogu.com.cn/problem/P7322)33.《注意到》$a+b=2\times(a\operatorname{and}b)+a\operatorname{xor}b$,例题[P10118 『STA - R4』And](https://www.luogu.com.cn/problem/P10118)(题解的做法## 小寄巧1.最值记录时初始值少开INT_MAX或25 行未改动```10.double 类型输出时要么保留几位,要么强制转int,因为它输出科学计数法形式,坠机记录[CF2055D Scarecrow](https://www.luogu.com.cn/problem/CF2055D)11.线段树覆盖时一定要仔细考虑是否会使答案不优,若有可能,线段树加一个形参控制硬修改和软修改,坠机记录[P2487 [SDOI2011] 拦截导弹](https://www.luogu.com.cn/problem/P2487)12.写不等式时没事别乱移项,小心符号反了,坠机记录[P2497 [SDOI2012] 基站建设](https://www.luogu.com.cn/problem/P2497)123444 行未改动49505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812925 行未改动155156157158159160161162163164165166167168169170## 小技巧1.推得不充分必要条件时,可以使用hash转为充要条件,例题[P8819 [CSP-S 2022] 星战](https://www.luogu.com.cn/problem/P8819)44 行未改动24.像买东西再卖掉这种贪心问题时,若感到不好贪,考虑将购买的每个物品的价值、数量同时放入单调队列贪心。25.[排列笑传之逆序列字典序不变而好处理](https://www.luogu.com.cn/problem/AT_agc001_f)26.[背包笑传之数量多猜种类少,多重背包开始洲际](https://www.luogu.com.cn/problem/CF1481F)27.[前缀和肘飞多重背包计数](https://www.luogu.com.cn/problem/AT_arc104_d)28.二项式定理应用例题[P10185 [YDOI R1] Necklace](https://www.luogu.com.cn/problem/P10185)29.[cdq洲飞dp](https://www.luogu.com.cn/problem/P2487)30.[cdq和斜率优化一起洲际dp](https://www.luogu.com.cn/problem/P2497)31.算方案数时若总方案数不好算,考虑什么时候会导致方案数变化,计算这个突变点,例题[P7322 「PMOI-4」排列变换](https://www.luogu.com.cn/problem/P7322)32.《注意到》$a+b=2\times(a\operatorname{and}b)+a\operatorname{xor}b$,例题[P10118 『STA - R4』And](https://www.luogu.com.cn/problem/P10118)(题解的做法)33.推式子枚举变量时,要保证不重不漏,最好也要保证有解。算贡献时可从期望入手,例题[P3228 [HNOI2013] 数列](https://www.luogu.com.cn/problem/P3228)34.[离线trie树上建fail树上建树剖套树状数组或可持久化线段树](https://www.luogu.com.cn/problem/P2414)35.AC自动机同时匹配两个字符串时,可以考虑将两个字符一起映射,字典树开unordered_map即可,例题[P14363 [CSP-S 2025] 谐音替换](https://www.luogu.com.cn/problem/P14363)36.写式子->数论化开->奇偶性分析,例题[CF1610D Not Quite Lee](https://www.luogu.com.cn/problem/CF1610D)37.区间上显然的决策单调性就用双指针,例题[CF1167E Range Deleting](https://www.luogu.com.cn/problem/CF1167E)38.[最短路变体,决策单调性删边](https://www.luogu.com.cn/problem/P9126)39.后缀数组上,经典的并查集维护区间合并,例题[P2178 [NOI2015] 品酒大会](https://www.luogu.com.cn/problem/P2178)40.遇到“第一个大”的条件,转化成前缀max数组上的关系。构造时可以考虑先强行构造,中途支持反悔,最后验证正确性即可,例题[P10134 [USACO24JAN] Cowmpetency S](https://www.luogu.com.cn/problem/P10134)41.推母函数时,形如$\frac{1}{ax^2+bx+c}$裂项为为$\frac{A}{1-ax}-\frac{B}{1-bx}$,例题[P4451 [国家集训队] 整数的lqp拆分](https://www.luogu.com.cn/problem/P4451)42.面对修改时先加后删某一元素,关注加和删哪个会立刻影响答案。若删才会,考虑正难则反,删改为加,例题[P8097 [USACO22JAN] Farm Updates G](https://www.luogu.com.cn/problem/P8097)43.往集合放入$2^{-k}$元素时,不妨先放$1$,之后整体反复除以$2$,以达到要放的元素,例题[AT_arc107_d [ARC107D] Number of Multisets](https://www.luogu.com.cn/problem/AT_arc107_d)44.递归的定义大概率是树上的定义,转化为树上问题,然后换用更简单的模型解决,例题[AT_arc186_d [ARC186D] Polish Mania](https://www.luogu.com.cn/problem/AT_arc186_d)45.[网格图上,不经过一条直线的反射容斥](https://www.luogu.com.cn/problem/AT_arc186_d)46.涉及前缀和的dp往往可以用之前的状态化简,然后注意转移方向,可能可以用双线反射容斥,例题[P3266 [JLOI2015] 骗我呢](https://www.luogu.com.cn/problem/P3266)47.给元素编号,且编号呈排列时,考虑不管排列,即可以重复,用容斥去重即可,例题[P3349 [ZJOI2016] 小星星](https://www.luogu.com.cn/problem/P3349)48.找性质,抓住能算尽量多的最优情况算,例题[P11802 【MX-X9-T6】『GROI-R3』Graph](https://www.luogu.com.cn/problem/P11802)49.算“恰好”方案时,利用二项式反演,用“至少”方案推得答案,例题[P6478 [NOI Online #2 提高组] 游戏](https://www.luogu.com.cn/problem/P6478)50.贪心优化dp,从最终结果上贪心选择,优化状态,例题[P8903 [USACO22DEC] Bribing Friends G](https://www.luogu.com.cn/problem/P8903)51.棋盘上dp时,很多时候想到一行一行dp,并且想到状压。但若每一列对后面所有行的影响一样时,不需将具体状态记录,仅需记录数量即可,例题[P2051 [AHOI2009] 中国象棋](https://www.luogu.com.cn/problem/P2051)52.贪心时如果被hack,先别急,想想为什么会被hack,可能就会因此发现性质,然后贪心优化dp,例题[P8162 [JOI 2022 Final] 让我们赢得选举 / Let's Win the Election](https://www.luogu.com.cn/problem/P8162)53.在区间dp时,若只关心一个区间中是否存在一种情况,不妨另设数组$g_{i}$,表示以$i$为左端点时,该情况出现的最小右端点,例题[P9746 「KDOI-06-S」合并序列](https://www.luogu.com.cn/problem/P9746)54.dp时若被卡空间,想想当前最远调用到哪,滚动数组优化,例题[P10119 『STA - R4』踱步](https://www.luogu.com.cn/problem/P10119)55.两个长度不对等的字符串匹配前缀时,考虑将短的加上任意字符使长度相等,例题[CF1336C Kaavi and Magic Spell](https://www.luogu.com.cn/problem/CF1336C)56.时限允许时,括号序列具有天然的区间dp性质,使用记搜实现会更清晰,例题[CF149D Coloring Brackets](https://www.luogu.com.cn/problem/CF149D)57.形如一个字符串中,可以将一个字母分裂成其他字母的问题,最终串肯定是一段一段、每段由一个字母分裂而来,于是考虑区间dp,例题[CF49E Common ancestor](https://www.luogu.com.cn/problem/CF49E)58.连续段dp,转化为往段里插入或新开一个段,例题[CF1515E Phoenix and Computers](https://www.luogu.com.cn/problem/CF1515E)59.构造题被特例卡时,可以考虑随机化强行构造。[随机化方法](https://www.luogu.com.cn/paste/zyf1yg5b),例题[CF2183D2 Tree Coloring (Hard Version)](https://www.luogu.com.cn/problem/CF2183D2)60.计数题,题目给出的条件为不等式时,考虑放缩出真正的范围,和所求取交集,可能就会有神奇结论,例题[CF2183E LCM is Legendary Counting Master](https://www.luogu.com.cn/problem/CF2183E)61.最大[汉明距离](https://baike.baidu.com/item/%E6%B1%89%E6%98%8E%E8%B7%9D%E7%A6%BB/475174?fr=aladdin)转化为反码求最小汉明距离,dp时考虑逐位变化的状压dp,例题[P9187 [USACO23OPEN] Field Day S](https://www.luogu.com.cn/problem/P9187)62.设计状态时$dp[i]$表示最小值为$i$还是最小值大于等于$i$应灵活变通,并且设计区间最小值时,考虑钦定某个位置就是最小值,加上两边区间大于等于最小值,例题[P3592 [POI 2015 R3] 洗车 Car washes](https://www.luogu.com.cn/problem/P3592)## 小寄巧1.最值记录时初始值少开INT_MAX或25 行未改动```10.double 类型输出时要么保留几位,要么强制转int,因为它输出科学计数法形式,坠机记录[CF2055D Scarecrow](https://www.luogu.com.cn/problem/CF2055D)11.线段树覆盖时一定要仔细考虑是否会使答案不优,若有可能,线段树加一个形参控制硬修改和软修改,坠机记录[P2487 [SDOI2011] 拦截导弹](https://www.luogu.com.cn/problem/P2487)12.写不等式时没事别乱移项,小心符号反了,坠机记录[P2497 [SDOI2012] 基站建设](https://www.luogu.com.cn/problem/P2497)13.公式别记错,坠机记录[P9823 [ICPC 2020 Shanghai R] The Journey of Geor Autumn](https://www.luogu.com.cn/problem/P9823)$\dbinom{n}{m}=\frac{(n)!}{m!(n-m)!}$14.样例有诈,不要乱猜结论,最好推式子,坠机记录[CF2178F Conquer or of Forest](https://www.luogu.com.cn/problem/CF2178F)15.博弈论一定要手玩一下,可能解没有那么多,特判特殊即可,坠机记录[CF1728D Letter Picking](https://www.luogu.com.cn/problem/CF1728D)16.hack自己时一定要举出正确的、具体的hack,小心hack正解,坠机记录[CF2183C War Strategy](https://www.luogu.com.cn/problem/CF2183C)## 何意味(把会,但很神秘)1.[寻找二次循环子串个数和](https://www.luogu.com.cn/problem/P1117)