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. hdu2713(dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2713 题意:有N个点,每个点都有一个值x,每次进行跳跃,当跳到自己所跳的第奇数个点是+x,第偶数个点时 ...

  2. HTML5之画布的拖拽/拖放

    <!DOCTYPE HTML> <html> <head> <script type="text/javascript"> func ...

  3. DB2错误代码

    db2错误代码大全 博客分类: 数据库 sqlcode sqlstate 说明 000 00000 SQL语句成功完毕 01xxx SQL语句成功完毕,可是有警告 +012 01545 未限定的列名被 ...

  4. Linux SSH端口转发

    SSH端口转发分为两种,一种是本地端口转发,又称为本地SSH隧道.一直是远程端口转发.SSH端口转发,还必须指定数据传送的目标主机,从而形成点对点的端口转发. 本地端口转发     假定有三台主机A. ...

  5. httpcomponents-client-4.3.x DOC

    Chapter 1. Fundamentals Prev     Next Chapter 1. Fundamentals 1.1. Request execution The most essent ...

  6. Unity3D入门(二):碰撞检測

    碰撞器由来 1.系统默认会给每一个对象(GameObject)加入一个碰撞组件(ColliderComponent),一些背景对象则能够取消该组件. 2.在unity3d中,能检測碰撞发生的方式有两种 ...

  7. 自定义JSTL函数标签(一)

    jstl标签库的配置 * 将jstl.jar和standard.jar拷贝到WEB-INF/lib下(如果使用el表达式,不用拷贝这两个jar) 注意:jstl必须在能够支持j2ee1.4/servl ...

  8. ecshop 全目录说明

    ECShop 2.5.1 的结构图及各文件相应功能介绍     ECShop2.5.1_Beta upload 的目录           ┣ activity.php 活动列表           ...

  9. login控件“您的登录尝试不成功。请重试”的解决方法

    原文:login控件"您的登录尝试不成功.请重试"的解决方法 遇到login控件“您的登录尝试不成功.请重试”报错之后,在网上找了很久,也按照如下帖子设置了 application ...

  10. POJ 1696 Space Ant(点积的应用)

    Space Ant 大意:有一仅仅蚂蚁,每次都仅仅向当前方向的左边走,问蚂蚁走遍全部的点的顺序输出.開始的点是纵坐标最小的那个点,開始的方向是開始点的x轴正方向. 思路:从開始点開始,每次找剩下的点中 ...