poj 1080
来源:互联网 发布:不以规矩不成方圆知乎 编辑:程序博客网 时间:2024/06/04 00:28
题目链接:http://poj.org/problem?id=1080
就是求基因的相似度,这个题是最长公共子序列的变形,状态方程:
dp[i][j]=Max(dp[i-1][j-1]+map[s1[i-1]][s2[j-1]],dp[i-1][j]+map[s1[i-1]][4],dp[i][j-1]+map[4][s2[j-1]]);
//dp[i][j]表示str1的前i个和str2的前j个的值//注意啊啊啊啊:str1[i]是串中第i+1个字符啊#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <map>//#include <iterator>using namespace std;int maxx(int a,int b){ return a > b ? a : b;}int main(){ string str1,str2; int n,a1,a2; int m[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} }; map<char,int> mapp; mapp['A'] = 0; mapp['C'] = 1; mapp['G'] = 2; mapp['T'] = 3; mapp['-'] = 4; int dp[101][101]; cin >> n; while(n--) { memset(dp,0,sizeof(dp)); cin >> a1 >> str1 >> a2 >> str2; dp[0][0] = 0; for(int i = 1; i <= a1; i ++) { //只有str1,那么str2全补 ‘-’ //str1前i个,str2没有,即dp[i][0]是由dp[i-1][0]加上m[str1中第i个字符]['-'],这里第i个,就是str1[i-1]啊。。。。此处被坑250次 dp[i][0] = dp[i-1][0] + m[ mapp[str1[i-1]] ][4]; } for(int i = 1; i <= a2; i++) { dp[0][i] = dp[0][i-1] + m [4][mapp[ str2[i-1] ]]; } for(int i = 1; i <= a1; i++) { for(int j = 1; j <= a2; j++) { dp[i][j] = maxx(dp[i-1][j-1] + m[ mapp[ str1[i-1] ] ][ mapp[ str2[j-1] ] ],maxx(dp[i][j-1] + m[4][ mapp[str2[j-1]] ],dp[i-1][j] + m[ mapp[str1[i-1]] ][4])); //cout << i <<" "<<j << " " <<dp[i][j]<<endl; } } cout <<dp[a1][a2]<<endl; } return 0;}
- POJ 1080
- POJ 1080
- POJ 1080
- poj 1080
- poj 1080
- poj 1080
- poj 1080
- POJ 1080
- poj-1080
- poj 1080
- poj 1080
- POJ 1080
- poj 1080
- POJ 1080
- poj 1080
- POJ 1080 LCS扩展!
- 【DP】 POJ 1080
- POJ 1080 (DP)
- Makefile - Build CPPs with each one has a main for apps
- Windows 下精减安装 QT
- poj 2406 Power Strings
- IPV6噩耗的开始
- C++课程教学改革问卷调查报告
- poj 1080
- 2012百度之星初赛第二场A题解答
- Linux下对已有项目快速打RPM包(只需编辑XML文件)
- 一个简单的SQL题目
- VxWorks系统的映像及其装载过程解析
- HOJ 1022 Spacecraft Malfunction
- android的apk之反编译
- 如何更改 MicrosoftInternet Explorer 中默认的 HTTP 保持连接值
- 作者Onlylupp魂の叫び