ACM PKU 1080 Human Gene Functions http://acm.pku.edu.cn/JudgeOnline/problem?id=1080
做了几天的一道题,一步一步向前推进,现在看着都想吐了,什么解题报告我也不想写了,就这样吧!
只有继续加油!!!
#include <iostream> using namespace std; char in_st[101]; char in_ed[101]; int gene[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 change( char c ) { if( c == 'A' ) return 0; if( c == 'C' ) return 1; if( c == 'G' ) return 2; if( c == 'T' ) return 3; if( c == '_' ) return 4; } int vl( char c1, char c2 ) { return gene [change(c1)] [change(c2)]; } int score[101][101]; int main() { int N; cin >> N; while (N--) { int m , n ,i ,j; cin >> m >>in_st; cin >> n >>in_ed; score[0][0] = 0; memset(score,0,sizeof(score)); for (i = 1;i <= m;i++) score[i][0] = score[i - 1][0] + vl(in_st[i-1], '_' ); for (j = 1;j <= n;j++) score[0][j] = score[0][j - 1] + vl('_', in_ed[j-1] ); int temp = 0; for (i = 1;i <= m;i++) { for (j = 1;j <= n;j++) { if (in_st[i-1] == in_ed[j-1]) score[i][j]= score[i-1][j-1] + 5 ; else { temp = score[i - 1][j-1] + vl(in_st[i-1], in_ed[j-1]); if (score[i][j - 1] + vl( '_', in_ed[j-1] ) > temp) temp = vl( '_', in_ed[j-1] ) + score[i][j - 1]; if (score[i - 1][j] + vl(in_st[i-1], '_' ) > temp) temp = vl( in_st[i-1], '_' ) + score[i - 1][j]; score[i][j]= temp ; } } } cout << score[m][n] <<endl; } return 0; }