poj 1080 human gene functions
来源:互联网 发布:java 单例设计模式 编辑:程序博客网 时间:2024/05/09 19:30
根据算法导论上面的思想来做,采用LCS的思想,但是在这里需要变换一下状态转移方程
这个跟核苷所占得比重有关系了
状态转移方程为:
c[i][j]=max(c[i-1][j-1]+value(a[i],b[j]),c[i-1][j]+value(a[i],'-'),c[i][j-1]+value('-',b[j]))
比较难的是边界条件的处理,这一点在源程序中将会有体现
#include<stdio.h>char a[105],b[105];int c[105][105];int value(char a,char b){int ret;switch(a){case 'A':{if(b=='A')ret=5;else if(b=='C')ret=-1;else if(b=='G')ret=-2;else if(b=='T')ret=-1;else if(b=='-')ret=-3;}break;case 'C':{if(b=='A')ret=-1;else if(b=='C')ret=5;else if(b=='G')ret=-3;else if(b=='T')ret=-2;else if(b=='-')ret=-4;}break;case 'G':{if(b=='A')ret=-2;else if(b=='C')ret=-3;else if(b=='G')ret=5;else if(b=='T')ret=-2;else if(b=='-')ret=-2;}break;case 'T':{if(b=='A')ret=-1;else if(b=='C')ret=-2;else if(b=='G')ret=-2;else if(b=='T')ret=5;else if(b=='-')ret=-1;}break;case '-':{if(b=='A')ret=-3;else if(b=='C')ret=-4;else if(b=='G')ret=-2;else if(b=='T')ret=-1;}break;}return ret;}int max(int a,int b,int c){int max=a;if(max<b)max=b;if(max<c)max=c;return max;}int main(){int T;scanf("%d",&T);while(T--){int m,n,i,j;scanf("%d%s",&m,a);scanf("%d%s",&n,b);for(i=m-1;i>=0;i--)a[i+1]=a[i];for(j=n-1;j>=0;j--)b[j+1]=b[j];c[0][0]=0;for(i=1;i<=m;i++) //这个地方的边界条件处理需要重视c[i][0]=value(a[i],'-')+c[i-1][0];for(j=1;j<=n;j++)c[0][j]=value('-',b[j])+c[0][j-1];for(i=1;i<=m;i++)for(j=1;j<=n;j++)c[i][j]=max(c[i-1][j-1]+value(a[i],b[j]),c[i-1][j]+value(a[i],'-'),c[i][j-1]+value('-',b[j]));printf("%d\n",c[m][n]);}return 0;}
- POJ 1080 Human Gene Functions
- POJ 1080 Human Gene Functions
- POJ 1080 Human Gene Functions
- poj 1080 Human Gene Functions
- POJ 1080 Human Gene Functions
- Poj 1080 Human Gene Functions
- poj 1080 Human Gene Functions
- poj 1080 Human Gene Functions
- POJ 1080 Human Gene Functions
- poj 1080 human gene functions
- POJ 1080 Human Gene Functions
- POJ 1080 Human Gene Functions
- POJ-1080-Human Gene Functions
- POJ 1080 Human Gene Functions
- POJ 1080 Human Gene Functions
- poj 1080 Human Gene Functions
- poj 1080 Human Gene Functions
- POJ 1080 Human Gene Functions
- 该跳槽了吗?
- jvm内存空间新对象申请活动图
- 昨天花开花谢
- 提高PHP编程效率的50个要点
- linux设备驱动总结
- poj 1080 human gene functions
- 9个offer,12家公司,35场面试,从微软到谷歌,应届计算机毕业生的2012求职之路
- 交叉编译linux内核
- ToString IFormattable 自定义格式化
- android 电池(二):android关机充电流程、充电画面显示
- ssh框架下tomcat启动时查询数据库
- yum更新时提示:另外一个程序锁定了 yum
- 内存那点事(一)总线
- 弹出对话框只有框体,没有内容