AGTC

Description

Let x and y be two strings over some finite alphabet A. We would like to transform x into y allowing only operations given below:

  • Deletion: a letter in x is missing in y at a corresponding position.
  • Insertion: a letter in y is missing in x at a corresponding position.
  • Change: letters at corresponding positions are distinct

Certainly, we would like to minimize the number of all possible operations.

Illustration

  1. A G T A A G T * A G G C
  2. | | | | | | |
  3. A G T * C * T G A C G C

Deletion: * in the bottom line

Insertion: * in the top line

Change: when the letters at the top and bottom are distinct

This tells us that to transform x = AGTCTGACGC into y = AGTAAGTAGGC we would be required to perform 5 operations (2 changes, 2 deletions and 1 insertion). If we want to minimize the
number operations, we should do it like

  1. A G T A A G T A G G C
  2. | | | | | | |
  3. A G T C T G * A C G C

and 4 moves would be required (3 changes and 1 deletion).

In this problem we would always consider strings x and y to be fixed, such that the number of letters in x is m and the number of letters in y is n where n ≥ m.

Assign 1 as the cost of an operation performed. Otherwise, assign 0 if there is no operation performed.

Write a program that would minimize the number of possible operations to transform any string x into a string y.

Input

The input consists of the strings x and y prefixed by their respective lengths, which are within 1000.

Output

An integer representing the minimum number of possible operations to transform any string x into a string y.

Sample Input

  1. 10 AGTCTGACGC
  2. 11 AGTAAGTAGGC

Sample Output

  1. 4

题意  给你两个DNA序列  求第一个第一个序列至少经过多次删除 、替换 或加入碱基得到第二个序列    事实上分析一下能够发现   仅仅要求出两个序列的最长公共子序列  这部分就能够不动了  然后较长序列的长度减去最长公共子序列的长度就是答案了

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. using namespace std;
  5. const int N = 1005;
  6. int la, lb, d[N][N];
  7. char a[N], b[N];
  8.  
  9. void lcs()
  10. {
  11. memset (d, 0, sizeof (d));
  12. for (int i = 1; i <= la; ++i)
  13. for (int j = 1; j <= lb; ++j)
  14. if (a[i] == b[j]) d[i][j] = d[i - 1][j - 1] + 1;
  15. else d[i][j] = max (d[i - 1][j], d[i][j - 1]);
  16. }
  17.  
  18. int main()
  19. {
  20. while (~scanf ("%d%s%d%s", &la, a + 1, &lb, b + 1))
  21. {
  22. lcs();
  23. printf ("%d\n", max (la, lb) - d[la][lb]);
  24. }
  25. return 0;
  26. }

版权声明:本文博客原创文章。博客,未经同意,不得转载。

POJ 3356 AGTC(最长公共子)的更多相关文章

  1. 【noi 2.6_2000】&【poj 2127】 最长公共子上升序列 (DP+打印路径)

    由于noi OJ上没有Special Judge,所以我是没有在这上面AC的.但是在POJ上A了. 题意如标题. 解法:f[i][j]表示a串前i个和b串前j个且包含b[j]的最长公共上升子序列长度 ...

  2. 使用后缀数组寻找最长公共子字符串JavaScript版

    后缀数组很久很久以前就出现了,具体的概念读者自行搜索,小菜仅略知一二,不便讨论. 本文通过寻找两个字符串的最长公共子字符串,演示了后缀数组的经典应用. 首先需要说明,小菜实现的这个后缀数组算法,并非标 ...

  3. POJ 3356 AGTC(最小编辑距离)

    POJ 3356 AGTC(最小编辑距离) http://poj.org/problem?id=3356 题意: 给出两个字符串x 与 y,当中x的长度为n,y的长度为m,而且m>=n.然后y能 ...

  4. uva 10066 The Twin Towers (最长公共子)

    uva 10066 The Twin Towers 标题效果:最长公共子. 解题思路:最长公共子. #include<stdio.h> #include<string.h> # ...

  5. POJ 2774 后缀数组:查找最长公共子

    思考:其实很easy.就在两个串在一起.通过一个特殊字符,中间分隔,然后找到后缀数组的最长的公共前缀.然后在两个不同的串,最长是最长的公共子串. 注意的是:用第一个字符串来推断是不是在同一个字符中,刚 ...

  6. POJ 3356.AGTC

    问题简述: 输入两个序列x和y,分别执行下列三个步骤,将序列x转化为y (1)插入:(2)删除:(3)替换: 要求输出最小操作数. 原题链接:http://poj.org/problem?id=335 ...

  7. POJ 1159 Palindrome(最长公共子序列)

    Palindrome [题目链接]Palindrome [题目类型]最长公共子序列 &题解: 你做的操作只能是插入字符,但是你要使最后palindrome,插入了之后就相当于抵消了,所以就和在 ...

  8. Palindrome--poj 1159(最长公共子字符串+滚动数字)

    http://poj.org/problem?id=1159 题目大意:  给你一个n  代表n个字符   第二行给你一个字符串  求使这个字符串变成回文字符串 最少需要添加多少个字符 分析:   原 ...

  9. POJ 1159 Palindrome 最长公共子序列的问题

    Description A palindrome is a symmetrical string, that is, a string read identically from left to ri ...

随机推荐

  1. C++ Primer中文版(第5版)

    <C++ Primer中文版(第5版)> 基本信息 作者: (美)Stanley B. Lippman(斯坦利 李普曼)    Josee Lajoie(约瑟 拉乔伊)    Barbar ...

  2. NGUI使用教程(3) 使用外部图片制作Atlas(图集)

    在实际操作之前有几个概念先弄清一下 Atlas:图集,把美术给你提供的素材,用 NGUI 的 Atlas Maker 工具.合成一张图片(准确的说,还同一时候生成了prefab.mat ). Spri ...

  3. Linux好书、经典书籍推荐

    Linux好书.经典书籍推荐 思想篇 <Linux/Unix设计思想> 图书将Unix与Linux的原理有效地结合起来,总结了Unix/Linux软件开发中的原则.在保留了第1版中Unix ...

  4. 关于AIX VG中 LV 的状态问题,LV STATE

    在数据库管理过程中常常遇见LV状态异常,而造成LV不能再次被使用的情况,那么AIX中LV的两种状态分别代表什么呢 如果是访问fs需要open,即创建文件系统并mount 文件系统LV STATE 才是 ...

  5. Linux------创建和终止进程

    创建进程: Linux创建两个步骤的新处理:fork()和exec().其中fork创建当前进程的能力(父进程)副本,那个孩子.父子进程只有PID不同.在这之后,该系统具有两个进程,运行相同的操作.父 ...

  6. 彻底理解Javascript原型继承

    彻底理解Javascript原型继承 之前写过一篇Javascript继承主题的文章,这篇文章作为一篇读书笔记,分析的不够深入. 本文试图进一步思考,争取彻底理解Javascript继承原理 实例成员 ...

  7. wamp5中的apache不能启动,80端口被占用

    在wamp中apache中的httpd.conf文件中 端口文件设置为8080 #Listen 12.34.56.78:8080Listen 8080

  8. Java EE (10) - 资源服务器的整合

    加密(Encryption)和数字签名(Digital Signature)通常被用于保护通讯--加密用来防止数据传输过程中的窃听--数字签名用来防止数据传输过程中的篡改 JDBC: 整合关系型数据库 ...

  9. HDU2586 How far away ?(LCA模板题)

    题目链接:传送门 题意: 给定一棵树,求两个点之间的距离. 分析: LCA 的模板题目 ans = dis[u]+dis[v] - 2*dis[lca(u,v)]; 在线算法:详细解说 传送门 代码例 ...

  10. android 图片浏览器 demo

    先上效果图,本demo 会逐步完好 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYTU2NTczMDE2NjEz/font/5a6L5L2T/fontsi ...