# 一、动态规划（1）相似基因

A G T G A T – G
– G T – – T A G

A G T G A T G
– G T T A – G

GENE.IN

7 AGTGATG

5 GTTAG
GENE.OUT
14

const
c:array [1..25] of longint=(5,-1,-2,-1,-3,-1,5,-3,-2,-4,-2,-3,5,-2,-2,-1,-2,-2,5,-1,-3,-4,-2,-1,0);
var
a:array [0..200,0..200] of longint;
b:array [1..5,1..5] of longint;
i,j,m,n,x,y,ans:longint;
s1,s2:string;

function f(ch:char):longint;
begin
if ch=’A’ then exit(1);
if ch=’C’ then exit(2);
if ch=’G’ then exit(3);
if ch=’T’ then exit(4);
end;

function max(x,y:longint):longint;
begin
if x>y then
exit(x);
exit(y);
end;

begin
assign(input,’gene.in’);
assign(output,’gene.out’);
reset(input);
rewrite(output);

for i:=1 to 5 do
for j:=1 to 5 do
b[i,j]:=c[i*5+j-5];
delete(s1,1,1);
delete(s2,1,1);
ans:=-10000000;
a[0,0]:=0;
for i:=1 to n do
a[0,i]:=b[5,f(s2[i])]+a[0,i-1];
for i:=1 to m do
a[i,0]:=b[f(s1[i]),5]+a[i-1,0];
for i:=1 to n do
for j:=1 to m do
begin
a[i,j]:=a[i-1,j]+b[f(s1[i]),5];
a[i,j]:=max(a[i,j-1]+b[5,f(s2[j])],a[i,j]);
a[i,j]:=max(a[i,j],a[i-1,j-1]+b[f(s1[i]),f(s2[j])]);
end;
writeln(a[n,m]);

close(input);
close(output);
end.

原文作者：动态规划
原文地址: https://blog.csdn.net/boyxiejunboy/article/details/46876115
本文转自网络文章，转载此文章仅为分享知识，如有侵权，请联系博主进行删除。