ACM学习-动态规划-基因查找序列问题

来源:互联网 发布:上班记录软件 编辑:程序博客网 时间:2024/05/20 18:50
// ACM学习-动态规划-基因查找序列问题.cpp : 定义控制台应用程序的入口点。
//


#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;


const int num = 101;
long score[num][num];
char a[101],//给定目标序列
     b[101],//数据库序列
     seq[101];//得到的最相似序列
int dp(){
long i, j, m, n;
m = strlen(a);//目标序列长度
n = strlen(b);//数据库序列长度
for (i = 0; i <= m; i++)score[i][n] = (m - i)*(-7);
for (j = 0; j <= n; j++)score[m][j] = (n - j)*(-7);
for (i = m - 1; i >= 0;i--)
for (j = n - 1; j >= 0; j--){
if (a[i] != b[j])score[i][j] = score[i + 1][j + 1] - 4;
else score[i][j] = score[i + 1][j + 1] + 5;
if (score[i + 1][j] - 7 > score[i][j]){
score[i][j] = score[i + 1][j] - 7;
}
if (score[i][j + 1] - 7 > score[i][j]){
score[i][j] = score[i][j + 1] - 7;
}
}
return score[0][0];
}


int _tmain(int argc, _TCHAR* argv[])
{
long i, n, max, p;
//scanf_s("%s %ld",a,&n);
cin >> a;
cin >> n;
for (i = 0; i < n; i++){
cin >> b;
//scanf_s("%s",b);
p = dp();
if (i == 0||p>max||(p==max&&strcmp(b,seq)<0)){
strcpy_s(seq,b);
max = p;
}

}
cout << max << ":" << seq << endl;
return 0;
}

0 0
原创粉丝点击