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 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
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,0,sizeof(dp));for(int i=1; i<=l1; i++){for(int j=1; j<=l2; j++){if(x[i-1]==y[j-1]){dp[i][j]=dp[i-1][j-1]+1;}else{dp[i][j]=max(dp[i-1][j],dp[i][j-1]);}}}int t=l1;if(l2>l1)t=l2;printf("%d\n",t-dp[l1][l2]);}return 0; }
转载于:https://www.cnblogs.com/yinbiao/p/9068107.html
POJ 3356 水LCS相关推荐
- POJ 2250 (LCS,经典输出LCS序列 dfs)
题目链接: http://poj.org/problem?id=2250 Compromise Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- poj入门水题整理1--按刷题顺序解释
1.1000 A+B 就是熟悉平台的一道题,下面有案例 2.1004 Financial Management 描述: Larry毕业之后挣钱了想知道他的财务状况,他现在有他的存款清单,想知道他12个 ...
- POJ 2291水题
题意:给你几根绳子,每根最大承重能力都不同,从中选出几根,问最大承重力量是多少?(比如有1,10,15承重的3跟绳子,如果用一根的话,选15的,能承重15,用2根的话,用10和15的,能承重10*2= ...
- POJ 3356 AGCT
经典LCS问题的变形 定义dp[i][j]为第一个串的前i个字符转化为第二个串的前j个字符所需最小的步骤,这是满足最优子结构性质的,因为如果转移到dp[i][j]的那个状态不是可以转化过来的状态中最优 ...
- POJ 3258 River Hopscotch (二分)
题目地址:POJ 3258 水题.二分距离,判断是否可行.需要注意的是最后一个,因为最后一个是没法移除的,所以还要倒着判断一下. 代码如下: #include <iostream> #in ...
- 魔法串 HDU - 4545(字符串dp)
小明和他的好朋友小西在玩一个新的游戏,由小西给出一个由小写字母构成的字符串,小明给出另一个比小西更长的字符串,也由小写字母组成,如果能通过魔法转换使小明的串和小西的变成同一个,那么他们两个人都会很开心 ...
- [kuangbin带你飞]专题十二 基础DP1
A - Max Sum Plus Plus (HDU 1024) 题意:将n个数取m段且不相交,求m段数字和最大值: dp[i][j]:前i个数字分成j段的最大值. 边界dp[0][0] = 0; d ...
- WC2018 乱搞记划雪记
pku WC 一月的长沙,久违地下了场雪,不,确切地说,是下了冰渣子.所有的道路和池塘都被冻得硬邦邦的,从寝室可以一路溜冰到科艺楼楼下. 正好赶上期末考试,据说下雪是为了衬托人物悲伤的心情. 不过一只 ...
- POJ 1159 Palindrome(字符串变回文:LCS)
POJ 1159 Palindrome(字符串变回文:LCS) http://poj.org/problem? id=1159 题意: 给你一个字符串, 问你做少须要在该字符串中插入几个字符能是的它变 ...
最新文章
- QTP连接oracle
- 【Win7下Android native code的编译和调试】
- ios 跳转到某 app 的评价区域、由某应用跳转到其他应用
- slam 常用数据集的帧率
- IDEA MAVEN Project 显示问题
- requests 返回的cookies为空_爬虫学习(2)(requests库)
- 百练 2972 确定进制 解题报告
- 【iOS】Ambiguous reference to member 'tableView(_:numberOfRowsInSection:)'
- 如何批量从Excel文件中导入数据到数据库(二)
- 从零开始学习makefile(7) makefile的filter的作用
- C# 修改打印机名称
- 快速排序(快排)——C语言实现
- z17刷机miui12教程_小米6刷miui12教程
- 交换机设备登录账号权限1_h3c交换机设置用户权限
- python 视频播放 拖动_python + opencv鼠标拖动视频区域裁剪
- B站最专业的DC漫威UP主,深度挖掘漫威故事内容。
- 人工智能学习笔记:基本遗传算法及其改进算法
- SpringBoot(二):详细讲解SpringBoot整合MyBatis
- 来,手写一个Operator (一)
- Ubuntu安装Eclipse,maven