【BZOJ3864】Hero meet devil DP套DP】的更多相关文章

Description There is an old country and the king fell in love with a devil. The devil always asks the king to do some crazy things. Although the king used to be wise and beloved by his people. Now he is just like a boy in love and can't refuse any re…
http://www.lydsy.com/JudgeOnline/problem.php?id=3864 题意: 给你一个DNA序列,求有多少个长度为m的DNA序列和给定序列的LCS为0,1,2.... 求LCS方式:f[i][j]=max(f[i-1][j],f[i][j-1],f[i-1][j-1]*(s[i]==t[j])) 固定了i,相邻的j的f[i][j]值最多相差1 dp[i][j] 表示长度为i的DNA序列,将“f[ |S| ][j+1]是否比f[ |S| ][j] 大1” 这个状…
Time Limit: 8 Sec  Memory Limit: 128 MBSubmit: 397  Solved: 206[Submit][Status][Discuss] Description There is an old country and the king fell in love with a devil. The devil always asks the king to do some crazy things. Although the king used to be…
题意:给你一个基因序列s(只有A,T,C,G四个字符,假设长度为n),问长度为m的基因序列s1中与给定的基因序列LCS是0,1......n的有多少个? 思路:最直接的方法是暴力枚举长度为m的串,然后再用求LCS的dp.当然我们可以在枚举的时候同时进行dp,但是复杂的仍然为O(4 ^ m).我们可以观察求LCS 的状态转移方程:dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) 若s[i] == s1[j] dp[i][j] = max(dp[i - 1][j…
最近写状压写的有点多,什么LIS,LCSLIS,LCSLIS,LCS全都用状压写了-这道题就是一道状压LCSLCSLCS 题意 给出一个长度为n(n<=15)n(n<=15)n(n<=15)的字符串sss,只由A,T,G,CA,T,G,CA,T,G,C组成.对于0...n0...n0...n的每一个iii,求长度为m(m<=1000)m(m<=1000)m(m<=1000)且只由A,T,G,CA,T,G,CA,T,G,C组成的串中,有多少字符串与sss的最长公共子序列(…
Description There is an old country and the king fell in love with a devil. The devil always asks the king to do some crazy things. Although the king used to be wise and beloved by his people. Now he is just like a boy in love and can’t refuse any re…
DP套DP,就是将内层DP的结果作为外层DP的状态进行DP的方法. [BZOJ3864]Hero meet devil 对做LCS的DP数组差分后状压,预处理出转移数组,然后直接转移即可. tr[S][k]表示当前差分状压后的状态为S,加入字符k(k为ACGT中一个)后会转移到什么状态. f[i][S]表示串已构造到第i位,和模式串的匹配状态差分后为S,的方案数. #include<cstdio> #include<cstring> #include<algorithm>…
[BZOJ3864]Hero meet devil Description There is an old country and the king fell in love with a devil. The devil always asks the king to do some crazy things. Although the king used to be wise and beloved by his people. Now he is just like a boy in lo…
3864: Hero meet devil 题意: 给你一个只由AGCT组成的字符串S (|S| ≤ 15),对于每个0 ≤ .. ≤ |S|,问 有多少个只由AGCT组成的长度为m(1 ≤ m ≤ 1000)的字符串T,使得\(LCS(T,S) = i\)? dp套dp! 通过一个外层的dp来计算使得另一个dp方程(子dp)最终结果为特定值的输入数. 一位一位确定子dp的输入,记录子dp的状态值 子dp: \(d(i,j)\)表示\(LCS(T[1,i],S[1,j])\),对第二维差分,\(…
Description Problem 5336. -- [TJOI2018]party Solution 神奇的dp套dp... 考虑lcs的转移方程: \[ lcs[i][j]=\begin{cases} lcs[i-1][j-1]+1 & (t[i]==s[j]) \\ \max (lcs[i-1][j],lcs[i][j-1]) \end{cases}\] 我们发现 \(lcs[i][j]-lcs[i][j-1] \le 1\),而且\(\left| S \right| \le 15\)…