poj 1080-Human Gene Functions

来源:互联网 发布:mac如何修改ppt格式 编辑:程序博客网 时间:2024/06/07 09:34

一开始毫无头绪啊。

后来看了LCS之后闭着眼自己写了一遍。


http://blog.csdn.net/v_july_v/article/details/6695482


#include<iostream>#include<string>using namespace std;unsigned char index(char letter){unsigned char ind = 4;switch(letter){case 'A':ind = 0;break;case 'C':ind = 1;break;case 'G':ind = 2;break;case 'T':ind = 3;break;case '-':ind = 4;break;default:;}return ind;}int max(int a,int b,int c){int out = a>b?a:b;out = out>c?out:c;return out;}int main(){char match[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 i=0,j=0,ii=0,jj=0,temp1,temp2,temp3;char s1[100],s2[100];int l1=0,l2=0;int samples = 0;int **lp=NULL;cin>>samples;for(i=0;i<samples;i++){cin>>l1;cin>>s1;cin>>l2;cin>>s2;lp = new int*[l1+1];lp[0] = new int[l2+1];lp[0][0] = 0;for (ii = 1;ii<=l1;ii++){lp[ii] = new int[l2+1];lp[ii][0] = lp[ii-1][0]+match[index(s1[ii-1])][index('-')];}for (jj = 1;jj<=l2;jj++){lp[0][jj] = lp[0][jj-1]+match[index(s2[jj-1])][index('-')];}for (ii = 1;ii<=l1;ii++){for (jj = 1;jj<=l2;jj++){temp1 = lp[ii-1][jj]+match[index(s1[ii-1])][index('-')];temp2 = lp[ii][jj-1]+match[index(s2[jj-1])][index('-')];temp3 = lp[ii-1][jj-1]+match[index(s2[jj-1])][index(s1[ii-1])];lp[ii][jj] = max(temp1,temp2,temp3);}}cout<<lp[l1][l2]<<endl;}    return 0;    }


0 0
原创粉丝点击