题目链接:

http://poj.org/problem?id=3356

AGTC
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 13855   Accepted: 5263

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 nm.

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

Source

分析:
两个序列中最长的序列长度减去LCS的长度
代码如下:
#include<cstring>
#include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>
#define max_v 1005
using namespace std;
char x[max_v],y[max_v];
int dp[max_v][max_v];
int l1,l2;
int main()
{
while(~scanf("%d %s",&l1,x))
{
scanf("%d %s",&l2,y);
memset(dp,,sizeof(dp));
for(int i=; i<=l1; i++)
{
for(int j=; j<=l2; j++)
{
if(x[i-]==y[j-])
{
dp[i][j]=dp[i-][j-]+;
}
else
{
dp[i][j]=max(dp[i-][j],dp[i][j-]);
}
}
}
int t=l1;
if(l2>l1)
t=l2;
printf("%d\n",t-dp[l1][l2]);
}
return ;
}

POJ 3356 水LCS的更多相关文章

  1. POJ 3356(最短编辑距离问题)

    POJ - 3356 AGTC Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Desc ...

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

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

  3. POJ 2250 Compromise(LCS)

    POJ 2250 Compromise(LCS)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#proble ...

  4. Poj 3356 ACGT(LCS 或 带备忘的递归)

    题意:把一个字符串通过增.删.改三种操作变成另外一个字符串,求最少的操作数. 分析: 可以用LCS求出最大公共子序列,再把两个串中更长的那一串中不是公共子序列的部分删除. 分析可知两个字符串的距离肯定 ...

  5. POJ 3356 AGTC(DP-最小编辑距离)

    Description Let x and y be two strings over some finite alphabet A. We would like to transform x int ...

  6. POJ 3356.AGTC

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

  7. poj 3356 AGTC(线性dp)

    题目链接:http://poj.org/problem?id=3356 思路分析:题目为经典的编辑距离问题,其实质为动态规划问题: 编辑距离问题定义:给定一个字符串source,可以对其进行复制,替换 ...

  8. POJ 2250 (LCS,经典输出LCS序列 dfs)

    题目链接: http://poj.org/problem?id=2250 Compromise Time Limit: 1000MS   Memory Limit: 65536K Total Subm ...

  9. POJ 1080( LCS变形)

    题目链接: http://poj.org/problem?id=1080 Human Gene Functions Time Limit: 1000MS   Memory Limit: 10000K ...

随机推荐

  1. 在生产环境中安全执行更新删除SQL脚本的技巧

    今天在生产环境上解决问题,由于广发银行的管理制度是开发公司是不允许确生产环境的,所以我们只能把要更新的语句发给运营中心,由运营中心的投产人员执行,我们则在旁边看着:在他执行的时候发现了一个很有趣的技巧 ...

  2. Android 原生 MediaPlayer 和 MediaCodec 的区别和联系(二)

    目录: (3)Android 官方网站 对 MediaPlayer的介绍 正文:  Android 官方网站 对 MediaPlayer的介绍         MediaPlayer      pub ...

  3. Mybatis显示SQL语句

    众所周知,hibernate可以通过配置show_sql在控制台显示sql语句,Mybatis可不可以呢?当然是可以的,将ibatis log4j运行级别调到DEBUG可以在控制台打印出ibatis运 ...

  4. html5 audio vedio and video.js

    查看audio play事件http://jplayer.org/HTML5.Media.Event.Inspector/ media.seekable, buffered,played这些数据 we ...

  5. SQL Server配置数据库邮件

    需求描述 在生产环境中,大部分情况下需要有自己的运维体制,包括自己健康状态的检测等.如果发生异常,需要提前预警的,可以以发邮件告知,邮件作为一种非常便利的预警实现方式,在及时性和易用性方面也有着不可替 ...

  6. form插件ajaxForm和ajaxSubmit方法传递对象参数说明

    form插件的ajaxForm和ajaxSubmit方法的Options对象还可以用来将值传递给jQuery的$.ajax方法.如果你熟悉$.ajax所支持的options,你可以利用它们来将Opti ...

  7. VUE入门准备------>ES6

    声明变量的方式:  var  let   const let  和 var的区别 var定义的变量是全局的会覆盖全局的定义 ; ;i<;i++){ console.log(i) } undefi ...

  8. Celery学习--- Celery 最佳实践之与django结合实现异步任务

    django 可以轻松跟celery结合实现异步任务,只需简单配置即可 同步执行和异步执行 注意:即使Celery的任务没有执行完成,但是已经创建了任务ID.可以利用前台的定时任务发送Ajax异步请求 ...

  9. Python学习---IO的异步[asyncio模块(no-http)]

    Asyncio进行异步IO请求操作: 1. @asyncio.coroutine  装饰任务函数 2. 函数内配合yield from 和装饰器@asyncio.coroutine 配合使用[固定格式 ...

  10. shell命令工作总结

    shell命令工作总结: 1.sed命令:1.1.将文本input.txt中含有”姓名”字符串的行中的谢朝辉替换成扎巴依:sed -e '/姓名/s/谢朝辉/扎巴依/g' input.txt1.2.将 ...