POJ 1080 LCS扩展!
来源:互联网 发布:螺栓重量计算软件 编辑:程序博客网 时间:2024/04/30 22:56
#include<cstdio>
#include<algorithm>
using namespace std;
#define A 0
#define C 1
#define G 2
#define T 3
#define MINUS 4
#define BUFSIZE 110
char p[BUFSIZE],q[BUFSIZE];
int rule[5][5] = {
{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}
};
int best[BUFSIZE][BUFSIZE];
int index(char a)
{
switch(a){
case 'A': return A;
case 'C': return C;
case 'G': return G;
case 'T': return T;
case '-': return MINUS;
}
}
int compute(char a,char b)
{
int i = index(a);
int j = index(b);
return rule[i][j];
}
int mymax(int i,int j,int k)
{
i = max(i,j);
i = max(i,k);
return i;
}
int main()
{
int cases;
scanf("%d",&cases);
for(int i=0;i<cases;i++){
int m,n;
scanf("%d",&m);
for(int j=0;j<=m+1;j++)p[j] = getchar();
scanf("%d",&n);
for(int j=0;j<=n+1;j++)q[j] = getchar();
p[0]='-',q[0]='-';
int sum = 0;
best[0][0] = 0;
for(int j=1;j<=n;j++)best[j][0] = best[j-1][0]+compute(p[j],'-');
for(int j=1;j<=n;j++)best[0][j] = best[0][j-1]+compute(q[j],'-');
//注意边界条件的计算。
for(int j=1;j<=m;j++)
for(int k=1;k<=n;k++)
best[j][k] = mymax(best[j-1][k]+compute(p[j],'-'),
best[j][k-1]+compute(q[k],'-'),
best[j-1][k-1]+compute(p[j],q[k]));
printf("%d/n",best[m][n]);
}
return 0;
}
- POJ 1080 LCS扩展!
- POJ-1159-Palindrome-lcs扩展
- poj 1080 LCS 应用
- POJ 1080 动态规划(LCS变种)
- POJ 1080 Human Gene Functions DP(LCS)
- POJ 1080 Human Gene Functions(LCS)
- POJ 1080 Human Gene Functions(LCS变形)
- POJ 1080 Human Gene Functions(DP LCS)
- POJ 1080 LCS变式dp
- poj 1080 Human Gene Functions lcs
- POJ 1080 Human Gene Functions(DP:LCS)
- POJ 1080 Human Gene Functions(LCS变形)
- poj 1159 Palindrome LCS
- poj 1159 Palindrome LCS
- poj 2533 LCS
- poj 3302 LCS水题
- poj 1159 LCS
- POJ 1458 LCS模板
- 中学生"黑客":攻击市政府信息网站只需几秒钟
- Delphi版的Base64转换函数(修改版)
- 读取TXT文件内容的方法
- dp
- 学习Linux系统的十一点建议
- POJ 1080 LCS扩展!
- Linux动态库(.so)搜索路径
- exchange发不出外部邮件
- asp.net(c#)如何读取上传过程中的.txt文件中的数据,并将其写入数据库的
- ASP.net AJAX置于框架中出现JScript运行时错误的解决方法
- asp.net 按行读取包含中文的文本(txt)文件并取得行数
- “实践型”高级软件工程师精英成就计划,向年薪10W冲刺!
- 【分享】印刷企业信息管理系统分析
- 密码生成器