金融信创如何推动金融服务效率与安全的全面提升
618
2022-10-05
bzoj 3864 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 love and can’t refuse any request from the devil. Also, this devil is looking like a very cute Loli.
After the ring has been destroyed, the devil doesn’t feel angry, and she is attracted by z*p’s wisdom and handsomeness. So she wants to find z*p out.
But what she only knows is one part of z*p’s DNA sequence S leaving on the broken ring.
Let us denote one man’s DNA sequence as a string consist of letters from ACGT. The similarity of two string S and T is the maximum common subsequence of them, denote by LCS(S,T).
After some days, the devil finds that. The kingdom’s people’s DNA sequence is pairwise different, and each is of length m. And there are 4^m people in the kingdom.
Then the devil wants to know, for each 0 <= i <= |S|, how many people in this kingdom having DNA sequence T such that LCS(S,T) = i.
You only to tell her the result modulo 10^9+7. Input
The first line contains an integer T, denoting the number of the test cases. For each test case, the first line contains a string S. the second line contains an integer m.
T<=5 |S|<=15. m<= 1000. Output
For each case, output the results for i=0,1,…,|S|, each on a single line. Sample Input
1 GTC 10 Sample Output
1 22783 528340 497452 HINT
Source
By WJMZBMR
非常有趣的一题
动态动态规划 省选考的板子题
考虑普通lcs是怎么做的
lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1],(lcs[i-1][j-1]+1)*(t[i]==s[j]))
考虑将i设置成第一个字符串的
然后j设置成 题目中S串的第j个位置
那么考虑我这个i属于的串是一个固定的串 那么考虑求lcs的时候是怎么求的
我会得到一个lcs矩阵 表示 lcs[i][j] 并且我知道 相邻的j-1~j只会最多+1 那么我们考虑 将i固定之后 获得lcs[i]生成的一个数组 然后对这个数组进行差分 那么可以得到一个0,1的序列 那么 就可以考虑把他们状压起来
于是首先预处理trans[s][owo]表示我当前匹配在第i-1个位置 我lcs第二维的差分状态为s 的情况下我再在s串中添加owo这个字母 新生成的第二维差分状态是多少
然后设dp[i][s]表示第一个串中我匹配到第i个位置 我lcs第二维状态差分之后是s 我的方案数是多少
然后最后统计的时候就循环所有状态数一下1的个数就是我lcs的个数 统计之后输出即可
#include
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~