hdu1080 Human Gene Functions(带权值最长公共子序列)
来源:互联网 发布:网络分销管理系统 编辑:程序博客网 时间:2024/04/28 05:54
带权值的最长公共子序列。
原本s1[i] == s2[j]时dp[i][j] = dp[i - 1][j - 1] + 1,现在变为dp[i][j] = dp[i - 1][j - 1] + Map[s1[i]][s2[j]]。
原本s1[i] != s2[j]时dp[i][j] = max(dp[i][j - 1],dp[i - 1][j] ),现在变为dp[i][j] = max(dp[i][j - 1] + Map['-'][s2[j]],dp[i - 1][j] + Map[s1[i]]['-'])。
而且既然都加上权值,就可以放在一起比较。同样初始化也要加权值。
还有打表注意的技巧,何必将字母变为数字?多麻烦。直接用字母表示下标就好了~
#include <stdio.h>#include <cstring>#include <algorithm>using namespace std;const int N = 105;const int INF = 1<<27;int Map[6][6];void init(){ Map['A']['A'] = Map['T']['T'] = Map['G']['G'] = Map['C']['C'] = 5; Map['A']['C'] = Map['C']['A'] = Map['A']['T'] = Map['T']['A'] = Map['T']['-'] = Map['-']['T'] = -1; Map['G']['A'] = Map['A']['G'] = Map['T']['C'] = Map['C']['T'] = Map['T']['G'] = Map['G']['T'] = Map['G']['-'] = Map['-']['G'] = -2; Map['C']['G'] = Map['G']['C'] = Map['A']['-'] = Map['-']['A'] = -3; Map['C']['-'] = Map['-']['C'] = -4;}int main(){ // freopen("in.txt", "r", stdin); init(); int dp[N][N]; int T, j, i, n, l1, l2; char s1[N], s2[N]; scanf("%d", &T); while(T --) { scanf("%d %s", &l1, s1 + 1); scanf("%d %s", &l2, s2 + 1); for(i = 0; i <= l1; i ++) for(j = 0; j <= l2; j ++) dp[i][j] = -INF; dp[0][0] = 0; for(i = 1; i <= l1; i ++) dp[i][0] = dp[i - 1][0] + Map[s1[i]]['-']; for(i = 1; i <= l2; i ++) dp[0][i] = dp[0][i - 1] + Map[s2[i]]['-']; for(i = 1; i <= l1; i ++) for(j = 1; j <= l2; j ++) dp[i][j] = max(dp[i - 1][j - 1] + Map[s1[i]][s2[j]], max(dp[i - 1][j] + Map[s1[i]]['-'], dp[i][j - 1] + Map['-'][s2[j]])); printf("%d\n", dp[l1][l2]); } return 0;}
0 0
- hdu1080 Human Gene Functions(带权值最长公共子序列)
- hdu1080 - Human Gene Functions 最长公共子序列推广
- Human Gene Functions(最长公共子序列变形题)
- ZOJ 1027 Human Gene Functions(最长公共子序列)
- hdu 1080 Human Gene Functions( 带权值的最长公共子序列)
- HDU 1080 Human Gene Functions(带权值的最长公共子序列)
- hdu1080 Human Gene Functions (DP动态规划,带权最长公共子串)
- hdu 1080 Human Gene Functions(类最长公共子序列)
- hdu 1080 Human Gene Functions (DP + 最长公共子序列)
- HDU 1080 Human Gene Functions (DP,最长公共子序列)
- 最长公共子序列及其变形(Human Gene Functions)(新加了一些内容)
- 【POJ1080】Human Gene Functions(动态规划 最长公共子序列)
- Hdu 1080 Human Gene Functions(最长公共子序列的变形)
- HDU 1080 Human Gene Functions--DP--(最长公共子序列变形)
- 【poj 1080】Human Gene Functions DP(类最长公共子序列*)
- hdu 1080 Human Gene Functions( 类似最长公共子序列)
- (POJ1080)Human Gene Functions <DP,最长公共子序列变形>
- POJ 1080 Human Gene Functions(最长公共子序列的特别版)
- Eclipse 与Android 模拟器断开连接
- 为Angularjs ngOptions加上index解决方案
- spring applicationContext.xml 配置文件 详解
- angular ngClick阻止冒泡,默认行为
- 为什么说DOM操作很慢
- hdu1080 Human Gene Functions(带权值最长公共子序列)
- angular controller as syntax vs scope
- focusout()与blur()的区别
- 求N的阶乘
- BFS ZOJ problem-1671 Waking Ant
- 利用browserify or requirejs 来构建angularjs
- x-template:一个简单高效的字符串模板引擎
- 《PYTHON源码剖析》的第十二章:Python虚拟机中的类机制 http://blog.sina.com.cn/s/blog_75984e830100yf3i.html
- 揭开AngularJS面纱