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

A G T A A G T * A G G C

| | |       |   |   | |

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

A  G  T  A  A  G  T  A  G  G  C

|  |  |        |     |     |  |

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

10 AGTCTGACGC
11 AGTAAGTAGGC

Sample Output

4

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

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 1005;
int la, lb, d[N][N];
char a[N], b[N]; void lcs()
{
memset (d, 0, sizeof (d));
for (int i = 1; i <= la; ++i)
for (int j = 1; j <= lb; ++j)
if (a[i] == b[j]) d[i][j] = d[i - 1][j - 1] + 1;
else d[i][j] = max (d[i - 1][j], d[i][j - 1]);
} int main()
{
while (~scanf ("%d%s%d%s", &la, a + 1, &lb, b + 1))
{
lcs();
printf ("%d\n", max (la, lb) - d[la][lb]);
}
return 0;
}

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

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. Hama学习总结

    Hama学习笔记 1.       Hama定义 Hama是基于HDFS上的BSP模型实现,其执行不须要MapReduce. 例证例如以下: 在单点调试的Hama系统上,仅仅执行NameNode.Da ...

  2. Java学习文件夹

    每天进步一点点,先研究一门语言深入研究下去.

  3. Matlab实现PCA

    在主成分分析(PCA)中,介绍了PCA的数学原理,其有用Matlab能够非常方便地对矩阵进行操作! 比方,用Matlab求多个样本的协方差矩阵.求矩阵的特征根和特征向量等. 以下介绍用Matlab实现 ...

  4. 修ecshop品牌筛选以LOGO图片形式显示

    如何实现商品列表页属性筛选区品牌筛选以LOGO形式展示,最模板总结ecshop/'>ecshop教程入下: 1.修改 category.php 文件,将(大概215行) $sql = " ...

  5. selenium 远程调用浏览器

    共分三步: 1.selenium官网下载selenium-server-standalone.jar的最新版本号 2.启动selenium-server::::: java -jar "se ...

  6. python学习笔记--for循环

    推荐一个学习语言的网站:http://www.codecademy.com 有教程,可以边学边写,蛮不错的. for循环: 1.for loops allow us to iterate throug ...

  7. 广域网佰腾玩O2O笑话——它看起来很漂亮,注定不低于

    据说 2014.8.29:中国最大的商业运营商万达在一起的互联网服务供应商百度.腾讯在深圳(属性)战略合作签约仪式举行. 从功能表面上.万达代表实体,百度代表数据.腾讯代表社区:按三个合伙人理解,是要 ...

  8. iOS设备定位

    一.iOS谈到定位 1.SignInSignOutViewController.h @interface SignInSignOutViewController : UIViewController& ...

  9. HTML&lt;!DOCTYPE&gt; 宣示

    在html页面,下面这行代码到底有什么用呢? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" & ...

  10. AutoFac使用方法总结:Part III

    生命周期 AutoFac中的生命周期概念非常重要,AutoFac也提供了强大的生命周期管理的能力. AutoFac定义了三种生命周期: Per Dependency Single Instance P ...