最长公共子序列的变形

题目大意:给出两个基因序列,求这两个序列的最大相似度。

题目中的表格给出了两两脱氧核苷酸的相似度。

状态转移方程为:

dp[i][j] = max(dp[i-1][j]+Similarity(s1[i], '-'),
                     dp[i][j-1]+Similarity(s2[j], '-'),
                     dp[i-1][j-1]+Similarity(s1[i], s2[j]));

注意边界的初始化。

  1. //#define LOCAL
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <algorithm>
  6. using namespace std;
  7.  
  8. char s1[], s2[];
  9. int dp[][];
  10.  
  11. int table[][] = {
  12. , -, -, -, -,
  13. -, , -, -, -,
  14. -, -, , -, -,
  15. -, -, -, , -,
  16. -, -, -, -,
  17. };
  18.  
  19. int max(int a, int b, int c)
  20. {
  21. return max(max(a, b), c);
  22. }
  23.  
  24. int f(char c)
  25. {
  26. if(c == 'A') return ;
  27. if(c == 'C') return ;
  28. if(c == 'G') return ;
  29. if(c == 'T') return ;
  30. if(c == '-') return ;
  31. }
  32.  
  33. int Similarity(char c1, char c2)
  34. { return table[f(c1)][f(c2)]; }
  35.  
  36. int main(void)
  37. {
  38. #ifdef LOCAL
  39. freopen("1080in.txt", "r", stdin);
  40. #endif
  41.  
  42. int T;
  43. scanf("%d", &T);
  44. while(T--)
  45. {
  46. int len1, len2, i, j;
  47. dp[][] = ;
  48. scanf("%d %s", &len1, s1+);
  49. scanf("%d %s", &len2, s2+);
  50. for(i = ; i <= len1; ++i)
  51. dp[i][] = dp[i-][] + Similarity(s1[i], '-');
  52. for(i = ; i <= len2; ++i)
  53. dp[][i] = dp[][i-] + Similarity(s2[i], '-');
  54. for(i = ; i <= len1; ++i)
  55. for(j = ; j <= len2; ++j)
  56. dp[i][j] = max(dp[i-][j]+Similarity(s1[i], '-'),
  57. dp[i][j-]+Similarity(s2[j], '-'),
  58. dp[i-][j-]+Similarity(s1[i], s2[j]));
  59.  
  60. printf("%d\n", dp[len1][len2]);
  61. }
  62. return ;
  63. }

代码君

HDU 1080 Human Gene Functions的更多相关文章

  1. HDU 1080 Human Gene Functions - 最长公共子序列(变形)

    传送门 题目大意: 将两个字符串对齐(只包含ACGT,可以用'-'占位),按照对齐分数表(参见题目)来计算最后的分数之和,输出最大的和. 例如:AGTGATG 和 GTTAG ,对齐后就是(为了表达对 ...

  2. hdu 1080 Human Gene Functions(DP)

    题意: 人类基因由A.C.G.T组成. 有一张5*5的基因表.每格有一个值,叫相似度.例:A-C:-3.意思是如果A和C配对, 则它俩的相似度是-3[P.S.:-和-没有相似度,即-和-不能配对] 现 ...

  3. poj 1080 ——Human Gene Functions——————【最长公共子序列变型题】

    Human Gene Functions Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17805   Accepted:  ...

  4. poj 1080 Human Gene Functions(lcs,较难)

    Human Gene Functions Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19573   Accepted:  ...

  5. POJ 1080 Human Gene Functions -- 动态规划(最长公共子序列)

    题目地址:http://poj.org/problem?id=1080 Description It is well known that a human gene can be considered ...

  6. poj 1080 Human Gene Functions(dp)

    题目:http://poj.org/problem?id=1080 题意:比较两个基因序列,测定它们的相似度,将两个基因排成直线,如果需要的话插入空格,使基因的长度相等,然后根据那个表格计算出相似度. ...

  7. dp poj 1080 Human Gene Functions

    题目链接: http://poj.org/problem?id=1080 题目大意: 给两个由A.C.T.G四个字符组成的字符串,可以在两串中加入-,使得两串长度相等. 每两个字符匹配时都有个值,求怎 ...

  8. P 1080 Human Gene Functions

    大概作了一周,终于A了 类似于求最长公共子序列,稍有变形 当前序列 ch1 中字符为 a,序列 ch2 中字符为 b 则有 3 种配对方式: 1. a 与 b 2. a 与 - 3. - 与 b 动态 ...

  9. POJ 1080 Human Gene Functions

    题意:给两个DNA序列,在这两个DNA序列中插入若干个'-',使两段序列长度相等,对应位置的两个符号的得分规则给出,求最高得分. 解法:dp.dp[i][j]表示第一个字符串s1的前i个字符和第二个字 ...

随机推荐

  1. 自定义TexturePacker插件导出自己的plist文件

    原地址:http://www.cppblog.com/sunicdavy/archive/2014/02/06/205645.html cocos2dx引擎使用plist文件, 一种特殊的xml格式作 ...

  2. MYSQL注入天书之数据库增删改介绍

    Background-4 增删改函数介绍 在对数据进行处理上,我们经常用到的是增删查改.接下来我们讲解一下mysql 的增删改.查就是我们上述总用到的select,这里就介绍了. 增加一行数据.Ins ...

  3. Sqli-labs less 53

    Less-53 和less51是一样的,只是这里的mysql错误不会在前台显示,但是对于stacked injection是一样的利用方式 http://127.0.0.1/sqli-labs/Les ...

  4. POJ 1742

    Coins Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 27580   Accepted: 9335 Descriptio ...

  5. HDU 2852 KiKi's K-Number(树状数组+二分搜索)

    题意:给出三种操作 0 e:将e放入容器中 1 e:将e从容器中删除,若不存在,则输出No Elment! 2 a k:搜索容器中比a大的第k个数,若不存在,则输出Not Find! 思路:树状数组+ ...

  6. HDU 1385 Minimum Transport Cost (Dijstra 最短路)

    Minimum Transport Cost http://acm.hdu.edu.cn/showproblem.php?pid=1385 Problem Description These are ...

  7. 如何在jmeter中调用自己写的java工具包

    本文介绍在jmeter中调用自己写java工具包,并非直接继承jmeter提供的java sample request接口. 工具/原料 jmeter eclipse 方法/步骤 通常用jmeter做 ...

  8. Android核心分析之二十八Android GDI之Surface&Canvas

    Surface&Canvas Canvas为在画布的意思.Android上层的作图几乎都通过Canvas实例来完成,其实Canvas更多是一种接口的包装.drawPaints ,drawPoi ...

  9. android-exploitme(五):不安全的数据存储

    今天我来看看如果android将数据存储在sdcard,它的权限是什么样的 1. 打开emm软件,做一笔转账.

  10. QT为QLabel添加Click事件(如果我们使用组件,我们关心的是信号槽;如果我们自定义组件,我们关心的是事件)

    其实就是改写了一个函数:mouseReleaseEvent,当在QLabel放开鼠标的时,就发射点击信号. #ifndef CLICKEDLABEL_H_ #define CLICKEDLABEL_H ...