POJ 3356 水LCS
题目链接:
http://poj.org/problem?id=3356
| 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 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
Source
#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的更多相关文章
- POJ 3356(最短编辑距离问题)
POJ - 3356 AGTC Time Limit: 1000MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64u Desc ...
- POJ 3356 AGTC(最小编辑距离)
POJ 3356 AGTC(最小编辑距离) http://poj.org/problem?id=3356 题意: 给出两个字符串x 与 y,当中x的长度为n,y的长度为m,而且m>=n.然后y能 ...
- POJ 2250 Compromise(LCS)
POJ 2250 Compromise(LCS)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#proble ...
- Poj 3356 ACGT(LCS 或 带备忘的递归)
题意:把一个字符串通过增.删.改三种操作变成另外一个字符串,求最少的操作数. 分析: 可以用LCS求出最大公共子序列,再把两个串中更长的那一串中不是公共子序列的部分删除. 分析可知两个字符串的距离肯定 ...
- POJ 3356 AGTC(DP-最小编辑距离)
Description Let x and y be two strings over some finite alphabet A. We would like to transform x int ...
- POJ 3356.AGTC
问题简述: 输入两个序列x和y,分别执行下列三个步骤,将序列x转化为y (1)插入:(2)删除:(3)替换: 要求输出最小操作数. 原题链接:http://poj.org/problem?id=335 ...
- poj 3356 AGTC(线性dp)
题目链接:http://poj.org/problem?id=3356 思路分析:题目为经典的编辑距离问题,其实质为动态规划问题: 编辑距离问题定义:给定一个字符串source,可以对其进行复制,替换 ...
- POJ 2250 (LCS,经典输出LCS序列 dfs)
题目链接: http://poj.org/problem?id=2250 Compromise Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- POJ 1080( LCS变形)
题目链接: http://poj.org/problem?id=1080 Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K ...
随机推荐
- 洛谷P4783 【模板】矩阵求逆(高斯消元)
题意 题目链接 Sol 首先在原矩阵的右侧放一个单位矩阵 对左侧的矩阵高斯消元 右侧的矩阵即为逆矩阵 // luogu-judger-enable-o2 #include<bits/stdc++ ...
- 【代码笔记】iOS-JASidePanelsDemo(侧滑)
一,效果图. 二,工程图. 三,代码. AppDelegate.h #import <UIKit/UIKit.h> @class JASidePanelController; @inter ...
- 涉及到【分页】的table的请求模式
step:1 点击分页器的内容 trigger事件句柄 (pagination, filters, sorter) => {//或者(page, pageSize)等 this.props.on ...
- 【node】用koa搭建一个增删改服务(一)
前文,vue分类里有一个日志demo的练习,这篇文章就是介绍针对日志demo的服务是怎么写的 一.koa搭建项目 1. npm init 2. npm install koa 二.建数据库 下面是项目 ...
- Android可伸缩布局-FlexboxLayout(支持RecyclerView集成)
Android可伸缩布局-FlexboxLayout(支持RecyclerView集成) 1 . 前言 前几天看到Google官方的博客介绍了Google开源的一个强大的布局-FlexboxLayou ...
- GridView双击行弹出窗口
protected void gvCustom_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == D ...
- Jupyter notebook 使用多个Conda 环境
conda install nb_conda_kernels
- sql 中的注释
1.单行注释 “-- ” 即:两个中滑线加一个空格 2.多行注释 "/* ... */" 示例: -- 单行注释 /* 多行注释*/ create table test(id i ...
- maven 编译打包时,明明类文件没有问题,却提示错误:未结束的字符串字面值,maven-compiler-plugin:2.3.2
maven错误提示如下: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (de ...
- 团队项目个人进展——Day03
一.昨天工作总结 冲刺第三天,昨天忙着整理数据结构相关知识,在团队项目上只是花了少部分时间来对地图的样式布局进行调整 二.遇到的问题 无 三.今日工作规划 继续昨天的规划,研究地图定位代码,并通过编写 ...