题目链接: https://codeforces.com/contest/1234/problem/F 题意: 给出一个只包含前20个小写字母的字符串,一次操作可以让一段字符颠倒顺序 最多一次这样的操作,让不出现相同字符的子串最长,求出最长长度 数据范围: $1\leq |S| \leq 1000 000$ 分析: 定义$dp[i]$代表,最多出现这些字符的连续串的最大长度 $i$是二进制状态枚举,某位有1,则可以出现这个字符 状态转移看代码 $ans=max(dp[i]+dp[1<<20-1…
CF1234F Yet Another Substring Reverse Description 给定一个字符串,可以任意翻转一个子串,求最终满足所有字符互不相同的子串的最大长度. 数据范围: \(n \le 10^6, \Sigma \le 20\) Solution 由于被翻转子串的选择是任意的,我们可以将最终的子串看作两个原串的前缀的后缀的拼合.由于题目的各种性质,我们只需要考虑所有子串构成的字符集的所有可能状态,而与位置无关. 而字符集的状态依然要求不能有重复字符,因此对于每一个位置的…
题目链接:http://codeforces.com/contest/219/problem/D 树dp //#pragma comment(linker, "/STACK:102400000, 102400000") #include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> #include…
怎么也没想到是子集DP,想到了应该就没什么难度了. 首先n>21时必定为NO. g[i][j]表示位置i后的第一个字母j在哪个位置,n*21求出. f[S]表示S的所有全排列子序列出现的最后末尾位置,枚举最后一个字母转移.21*2^21 #include<cstdio> #include<cstring> #include<algorithm> #define rep(i,l,r) for (int i=(l); i<=(r); i++) using nam…
题目链接 loj300 题解 orz litble 膜完题解后,突然有一个简单的想法: 考虑到\(2\)是质数,考虑Lucas定理: \[{n \choose m} = \prod_{i = 1} {\lfloor \frac{n}{2^{i - 1}} \rfloor \mod 2^i \choose \lfloor \frac{m}{2^{i - 1}} \rfloor \mod 2^i} \pmod 2\] 即 \[{n \choose m} = \prod_{each.bit.of.n.…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5823 看博客:http://www.cnblogs.com/SilverNebula/p/5929550.html 学到了求子集中独立集的姿势~ 还有那个子集DP真是太妙了! 代码如下: #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace…
明显是一道斯坦纳树的题. 然而这题只需要属性相同的点互相连接. 我们还是照常先套路求出\(ans[s]\). 然后对\(ans[s]\)做子集DP即可. 具体看代码. #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<algorithm> #include<queue> using namespace std; const in…
2560: 串珠子 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 757  Solved: 497[Submit][Status][Discuss] Description 铭铭有n个十分漂亮的珠子和若干根颜色不同的绳子.现在铭铭想用绳子把所有的珠子连接成一个整体. 现在已知所有珠子互不相同,用整数1到n编号.对于第i个珠子和第j个珠子,可以选择不用绳子连接,或者在ci,j根不同颜色的绳子中选择一根将它们连接.如果把珠子看作点,把绳子看作边,将所…
[CodeForces - 1272D] Remove One Element [线性dp] 标签:题解 codeforces题解 dp 线性dp 题目描述 Time limit 2000 ms Memory limit 262144 kB Source Codeforces Round #605 (Div. 3) Tags brute force   dp   *1500 Site https://codeforces.com/problemset/problem/1272/D 题面 Exam…
Substring Reverse Problem Two strings s and t of the same length are given. Determine whether it is possible to make t from s using exactly one reverse of some its substring. Input The first line contains the string s, and the second - the string t.…