zoj 1027 - Human Gene Functions
来源:互联网 发布:php获取字符串每个字母 编辑:程序博客网 时间:2024/04/29 10:03
题目:计算两个DNA串的,最大权值公共子序列。
分析:dp,LCS。
说明:注意初始化。(2011-09-19 09:49)
#include <iostream>#include <cstdlib>using namespace std;int Geno[ 210 ][ 210 ];int Matr[ 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 V( char C ){ switch( C ) { case 'A': return 0; case 'C': return 1; case 'G': return 2; case 'T': return 3; case '-': return 4; }}char A[ 110 ];char B[ 110 ];int main(){ int t,n,m; while ( cin >> t ) while ( t -- ) { cin >> n >> A >> m >> B; for ( int i = 0 ; i <= n ; ++ i ) for ( int j = 0 ; j <= m ; ++ j ) Geno[ i ][ j ] = -11111; Geno[ 0 ][ 0 ] = 0; for ( int i = 1 ; i <= n ; ++ i ) Geno[ i ][ 0 ] = Geno[ i-1 ][ 0 ] + Matr[ V( A[ i-1 ] ) ][ V( '-' ) ]; for ( int j = 1 ; j <= m ; ++ j ) Geno[ 0 ][ j ] = Geno[ 0 ][ j-1 ] + Matr[ V( '-' ) ][ V( B[ j-1 ] ) ]; for ( int i = 1 ; i <= n ; ++ i ) for ( int j = 1 ; j <= m ; ++ j ) { if ( Geno[ i-1 ][ j ] + Matr[ V( A[ i-1 ] ) ][ V( '-' ) ] > Geno[ i ][ j ] ) Geno[ i ][ j ] = Geno[ i-1 ][ j ] + Matr[ V( A[ i-1 ] ) ][ V( '-' ) ]; if ( Geno[ i ][ j-1 ] + Matr[ V( '-' ) ][ V( B[ j-1 ] ) ] > Geno[ i ][ j ] ) Geno[ i ][ j ] = Geno[ i ][ j-1 ] + Matr[ V( '-' ) ][ V( B[ j-1 ] ) ]; if ( Geno[ i-1 ][ j-1 ] + Matr[ V( A[ i-1 ] ) ][ V( B[ j-1 ] ) ] > Geno[ i ][ j ] ) Geno[ i ][ j ] = Geno[ i-1 ][ j-1 ] + Matr[ V( A[ i-1 ] ) ][ V( B[ j-1 ] ) ]; } cout << Geno[ n ][ m ] << endl; } return 0;}
0 0
- ZOJ-1027-Human Gene Functions
- zoj 1027 Human Gene Functions
- ZOJ 1027 Human Gene Functions
- ZOJ 1027 Human Gene Functions
- Zoj 1027 Human Gene Functions
- zoj 1027 Human Gene Functions
- zoj 1027 - Human Gene Functions
- ZOJ 1027 Human Gene Functions (DP)
- HDU 1080 || ZOJ 1027 Human Gene Functions
- zoj 1027 DP Human Gene Functions
- ZOJ 1027 Human Gene Functions(dp)
- ZOJ 1027 Human Gene Functions
- ZOJ 1027 Human Gene Functions(最长公共子序列)
- ZJU 1027 Human Gene Functions
- zju 1027-Human Gene Functions
- zoj1027 Human Gene Functions
- 1080 Human Gene Functions
- PKU1080 Human Gene Functions
- android多线程3
- 用正则表达式解析XML文档
- 大数乘法C实现
- android broadcast
- IAT HOOK
- zoj 1027 - Human Gene Functions
- ACM-专题总揽
- android 应用之短信拦截代码结构
- Python(三):使用Apache运行Python程序
- UCOS-II:对于信号量,互斥信号量,事件标志组的个人理解-转
- Div鼠标移动效果
- HDU 5052 Yaoge’s maximum profit(树链剖分+线段树,2014上海网络赛1011)
- zoj 1163 - The Staircases
- Ubuntu下Thinkpad风扇配置