POJ 3356 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 CDeletion: * 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(最长公共子)的更多相关文章
- 【noi 2.6_2000】&【poj 2127】 最长公共子上升序列 (DP+打印路径)
由于noi OJ上没有Special Judge,所以我是没有在这上面AC的.但是在POJ上A了. 题意如标题. 解法:f[i][j]表示a串前i个和b串前j个且包含b[j]的最长公共上升子序列长度 ...
- 使用后缀数组寻找最长公共子字符串JavaScript版
后缀数组很久很久以前就出现了,具体的概念读者自行搜索,小菜仅略知一二,不便讨论. 本文通过寻找两个字符串的最长公共子字符串,演示了后缀数组的经典应用. 首先需要说明,小菜实现的这个后缀数组算法,并非标 ...
- POJ 3356 AGTC(最小编辑距离)
POJ 3356 AGTC(最小编辑距离) http://poj.org/problem?id=3356 题意: 给出两个字符串x 与 y,当中x的长度为n,y的长度为m,而且m>=n.然后y能 ...
- uva 10066 The Twin Towers (最长公共子)
uva 10066 The Twin Towers 标题效果:最长公共子. 解题思路:最长公共子. #include<stdio.h> #include<string.h> # ...
- POJ 2774 后缀数组:查找最长公共子
思考:其实很easy.就在两个串在一起.通过一个特殊字符,中间分隔,然后找到后缀数组的最长的公共前缀.然后在两个不同的串,最长是最长的公共子串. 注意的是:用第一个字符串来推断是不是在同一个字符中,刚 ...
- POJ 3356.AGTC
问题简述: 输入两个序列x和y,分别执行下列三个步骤,将序列x转化为y (1)插入:(2)删除:(3)替换: 要求输出最小操作数. 原题链接:http://poj.org/problem?id=335 ...
- POJ 1159 Palindrome(最长公共子序列)
Palindrome [题目链接]Palindrome [题目类型]最长公共子序列 &题解: 你做的操作只能是插入字符,但是你要使最后palindrome,插入了之后就相当于抵消了,所以就和在 ...
- Palindrome--poj 1159(最长公共子字符串+滚动数字)
http://poj.org/problem?id=1159 题目大意: 给你一个n 代表n个字符 第二行给你一个字符串 求使这个字符串变成回文字符串 最少需要添加多少个字符 分析: 原 ...
- POJ 1159 Palindrome 最长公共子序列的问题
Description A palindrome is a symmetrical string, that is, a string read identically from left to ri ...
随机推荐
- Django URL 命名空间
https://docs.djangoproject.com/en/1.5/topics/http/urls/#introduction 译文: URL 命名空间 简介: 当你需要部署一个应用的多个实 ...
- 【译】ASP.NET MVC 5 教程 - 7:Edit方法和Edit视图详解
原文:[译]ASP.NET MVC 5 教程 - 7:Edit方法和Edit视图详解 在本节中,我们继续研究生成的Edit方法和视图.但在研究之前,我们先将 release date 弄得好看一点.打 ...
- SWT实践过程中遇到的问题
1.import org.eclipse.swt.widgets.Text; 诸如右所示的找不到这个包. 解决办法:project->properties->build path-> ...
- PS顶级胶片滤镜插件 Alien Skin Exposure v6.x最新通用汉化补丁
Alien Skin Exposure v6.0 是一款专业的PS胶片调色滤镜软件,使用Alien Skin Exposure可以迅速将照片调出各种胶片效果,如电影胶片.宝丽来胶片效果.波拉潘胶片效果 ...
- zimbra启用SMTP认证并绑定认证登录和发件人
1. smtp认证 1.1 修改mynetworks 登录zimbra后台-->全局配置-->MTA-->信任网络-->127.0.0.0/8 ...
- 一个测试SQL2005数据库连接JSP档
在这里,在SQL 2005中间InterLib数据库案例.得到InterLib/tb_booktype目录. 的影响,如下面的: watermark/2/text/aHR0cDovL2Jsb2cuY3 ...
- windows phone xaml文件中元素及属性(10)
原文:windows phone xaml文件中元素及属性(10) Textblock xaml文件和隐藏文件 在设计界面的时候我们可以通过xaml中进行设计,这种设计是所见即所得的,很是方便,由于x ...
- [置顶] 最优间隔分类器、原始/对偶问题、SVM的对偶问题——斯坦福ML公开课笔记7
转载请注明:http://blog.csdn.net/xinzhangyanxiang/article/details/9774135 本篇笔记针对ML公开课的第七个视频,主要内容包括最优间隔分类器( ...
- Ubuntu下hadoop2.4搭建集群(单机模式)
一 .新建用户和用户组 注明:(这个步骤事实上能够不用的.只是单独使用一个不同的用户好一些) 1.新建用户组 sudo addgroup hadoop 2.新建用户 sudo adduser -in ...
- C语言程序代写(Linux下线程)
联系QQ:928900200 CSCI 3120 Operating Systems Summer 2014 Handout 3Assignment 2Date Due: June 5, 2014 b ...