Description
一个基因串只由四个字母组成。
给出一个长度为
N
,仅有四个字母组成的字符串
Data Constraint
Solution
考虑动态规划,设
Fi,j
表示构造的基因串构造到了第
i
位,
分析上述做法的时间复杂度,由于最多只有
N
个前缀,且每个前缀的与构造的串的最长公共子序列的长度最多不过
可以发现并不是
j
代表的所有状态都是有意义的。
设
令
Gi
=
max
(
Rj
) (
1
≤
令
现在使
j
对应
Code(Pascal)
const mo=1000000007;
var
wz:array[1..4] of char=('A','C','G','T');
ch:array[0..100] of char;
ans:array[0..1000] of qword;
g,m2,gg:array[0..15] of longint;
n,m,h,j,k,l,i,o,p:longint;
f:array[0..2000,0..2048] of qword;
function max(a,b:longint):longint;
begin if a>b then exit(a) else exit(b); end;
begin
while not(eoln) do begin
inc(n); read(ch[n]);
end;
readln(m); p:=1; for i:=1 to n do p:=p*2; dec(p);
m2[1]:=1; for i:=2 to n do m2[i]:=m2[i-1]*2;
f[0,0]:=1;
for i:=0 to m-1 do
for j:=0 to p do
begin
f[i,j]:=f[i,j] mod mo; if f[i,j]=0 then continue;
for l:=1 to n do if j and m2[l]>0 then g[l]:=g[l-1]+1 else g[l]:=g[l-1];
for k:=1 to 4 do
begin
for l:=1 to n do
if ch[l]=wz[k] then gg[l]:=max(gg[l-1],g[l-1]+1)
else gg[l]:=max(gg[l-1],g[l]);
h:=0; for l:=1 to n do h:=h+m2[l]*(gg[l]-gg[l-1]);
f[i+1,h]:=f[i+1,h]+f[i,j];
end;
end;
for i:=0 to p do
begin
h:=0; for l:=1 to n do if i and m2[l]>0 then inc(h);
ans[h]:=(ans[h]+f[m,i]) mod mo;
end;
for i:=0 to n do writeln(ans[i]);
end.