大意: 给定字符串$s$, $p$, 对于$0\le x\le |s|$, 求$s$删除$x$个字符后, $p$在$s$中的最大出现次数. 显然答案是先递增后递减的, 那么问题就转化求最大出现次数为$y$时, 求$S$所需要删除的最少字符数. 先暴力O(n^2)求出以每个字符开头匹配完一个$p$后的最小右端点, 然后$dp$即可. #include <iostream> #include <sstream> #include <algorithm> #include &…
大意:给定长$n$的字符串$s$, 只含'a','b','?', '?'可以替换为任意字符, 在给定长$t$的字符串, "ababab...", 求替换尽量少的'?', 使得$s$能匹配最多的不相交的$t$. 先不考虑最少替换的限制, 要尽量多的匹配$t$, 可以先预处理出可以匹配的位置, 然后$dp$. 要求最小的话, 每次$dp$转移时可能有多个转移点, 对每个dp值维护一个前缀最小值即可. #include <iostream> #include <iostre…
大意: 给定字符串S, 要求维护三个串, 支持在每个串末尾添加或删除字符, 询问S是否能找到三个不相交的子序列等于三个串. 暴力DP, 若不考虑动态维护的话, 可以直接$O(len^3)$处理出最少需要S中前多少位能匹配. 考虑添加删除的话, DP刷表, $O(len^2q)$ #include <iostream> #include <iostream> #include <algorithm> #include <cstdio> #include <…
大意: 给定字符串$s$, 长度为$n$, 取$k=\lfloor log2(n)\rfloor$, 第$i$次操作删除一个长度为$2^{i-1}$的子串, 求一种方案使得, $k$次操作后$s$的字典序最小, 输出删除后的字符串. 考虑一些弱化的情况, 每次均删除长为$2$的子串, 共删除$k$次 那么很容易得出$O(n^3)$的$DP$. int n, k; string s, dp[N][N]; int main() { cin>>s>>k; n = s.size(); RE…
大意: 给定字符串$a$,$b$, $b$可以任选一段连续的区间删除, 要求最后$b$是$a$的子序列, 求最少删除区间长度. 删除一段连续区间, 那么剩余的一定是一段前缀和后缀. 判断是否是子序列可以用序列自动机, 最后双指针合并前缀与后缀的答案. #include <iostream> #include <sstream> #include <algorithm> #include <cstdio> #include <math.h> #in…
题目链接: http://www.codeforces.com/contest/476/problem/E E. Dreamoon and Strings time limit per test 1 secondmemory limit per test 256 megabytes 问题描述 Dreamoon has a string s and a pattern string p. He first removes exactly x characters from s obtaining…
E. Dreamoon and Strings 题目连接: http://www.codeforces.com/contest/476/problem/E Description Dreamoon has a string s and a pattern string p. He first removes exactly x characters from s obtaining string s' as a result. Then he calculates that is defined…
E. Dreamoon and Strings time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Dreamoon has a string s and a pattern string p. He first removes exactly x characters from s obtaining string s' as a…
C. Dreamoon and Strings time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Dreamoon has a string s and a pattern string p. He first removes exactly x characters from s obtaining string s' as a…
题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=28214 题目大意:源串有如下变形:每次将串切为两半,位置颠倒形成新串.问经过K次变形后,与目标串相同的变形方案数.mod 1000000007. 解题思路: 奇葩的字符串DP.照着别人的题解写的,解释不出原理是什么. 首先统计出经过1次变形,就能和目标串相同的中间产物串(包含源串)的个数cnt.len表示源串长度,那么len-cnt就表示和目标串不同的个数. 用…