P1140 相似基因

 

https://www.luogu.org/problemnew/show/P1140

 

 1 #include<iostream>
 2 #include<cstdio>
 3 #include <cctype>
 4 #include<algorithm>
 5 #include<cstring>
 6 #include<cmath>
 7 #include<string>
 8 #include<cmath>
 9 #include<set>
10 #include<vector>
11 #include<stack>
12 #include<queue>
13 #include<map>
14 using namespace std;
15 #define ll long long
16 #define mem(a,x) memset(a,x,sizeof(a))
17 #define se second
18 #define fi first
19 const int INF= 0x3f3f3f3f;
20 const int N=1e4+5;
21 
22 int len1,len2;
23 char a[105],b[105]; 
24 int f[105][105];
25 
26 int d[5][5]={{5,-1,-2,-1,-3},
27              {-1,5,-3,-2,-4},
28              {-2,-3,5,-2,-2},
29              {-1,-2,-2,5,-1},
30              {-3,-4,-2,-1,0}};
31              
32 map<char,int>m;
33 int main()
34 {
35     cin>>len1; scanf("%s",a+1);
36     cin>>len2; scanf("%s",b+1);
37     m['A']=0;
38     m['C']=1;
39     m['G']=2;
40     m['T']=3;
41     m[' ']=4;
42     
43     mem(f,-0x3f3f);
44     f[0][0]=0;
45     for(int i=0;i<=len1;i++)
46     {
47         for(int j=0;j<=len2;j++)
48         {
49             if(i&&j)
50                 f[i][j]= max( f[i][j], f[i-1][j-1]+d[ m[a[i]] ][ m[b[j]] ]);
51             if(i) //i有字母,j为空格 
52                 f[i][j]= max( f[i][j], f[i-1][j]+d[ m[a[i]] ][ m[' '] ]);
53             if(j)//j为字母,i为空格 
54                 f[i][j]= max( f[i][j], f[i][j-1]+d[ m[' '] ][ m[b[j]] ]);
55         }
56     }
57     cout<<f[len1][len2]<<endl;
58 }

 

posted @ 2018-08-06 15:16  木流牛马  阅读(176)  评论(0编辑  收藏  举报