POJ 3356 AGTC 解题报告(Edit Distance,DP)

pku acm 3356 AGTC Java代码 pku acm 第3356题 AGTC Java代码,有详细的注释,动态规划 立即下载
AGTC
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 9579 Accepted: 3659

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

   

    解题报告: 今天比赛被坑的一个地方,题目中出现了Edit Distance,却不知道具体是个什么东西,一直以为用LCS就可以搞定,然后一直WA。 

    以为是LCS也有先入为主的思想在里面,听到别人这么说,就直接以为就是这样,没有去想别的。

    Edit Distance就是两个串通过添加一个字符,删除一个字符,修改一个字符这样的变换,得到相同的串的步骤数。

    直接DP就好了。代码如下:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

char a[1111], b[1111];
int dp[1111][1111];

int dfs(int l, int r)
{
    if(l==0 && r==0) return 0;
    if(l==0 && r) return r;
    if(l && r==0) return l;

    if(~dp[l][r]) return dp[l][r];
    int &ans=dp[l][r];

    ans=min(min(dfs(l-1, r)+1, dfs(l, r-1)+1), dfs(l-1, r-1)+(a[l]!=b[r]));
    return ans;
}

int main()
{
    int lena, lenb;
    while(~scanf("%d%s%d%s", &lena, a+1, &lenb, b+1))
    {
        memset(dp, -1, sizeof(dp));
        printf("%d\n", dfs(lena, lenb));
    }
}


Python地理空间数据库之geopandas使用详解 地理空间数据分析在许多领域中都有着广泛的应用,包括地理信息系统(GIS)、城市规划、环境科学、地质勘探等。Python GeoPandas是一个强大的库,旨在简化地理空间数据的处理和分析。本文将深入介绍GeoPandas库,包括其基本概念、功能特性、示例代码以及在实际应用中的应用场景。 阅读详情

相关推荐

STM32L476低功耗实战:LPTIM精准定时唤醒STOP2模式与系统级功耗优化

本文深入探讨了STM32L476低功耗实战技巧,重点解析了LPTIM精准定时唤醒STOP2模式的配置与优化。通过详细的步骤指南和实战经验分享,帮助开发者实现系统级功耗优化,特别适合电池供电设备开发。文章涵盖LPTIM1定时器配置、STOP2模式进入流程及常见问题排查,助力将整机功耗降至8.2uA级别。

weixin_33686714的博客 439

poj 3356 编辑距离(空间优化)

AGTC Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7780   Accepted: 3087 Description Let x and y be two strings over some finite alphabet A. We would lik

keynumber的专栏 1423

通讯接口应用笔记3:使用W5500实现Modbus TCP服务器

  前面我们设计实现了W5500的驱动程序,也讲解了驱动的使用方式。在最近一次的项目应用中,正好有一个使用W5500实现TCP通讯的需求,所以我们就使用该驱动程序轻松实现。这一篇中我们就来说一说基于我们W5500通讯驱动程序实现TCP通讯的过程。 1、应用需求   在本次应用中,要求实现一个基于W5500的Modbus TCP服务器。这个需求的描述虽然只有一句话,但是这个需求的内容可不简单。我们首先来分析一下这个需求的具体内容。   为了实现基于W5500的Modbus TCP服务器,我们必先须基于W550

木南创智 5504

POJ 3356 AGTC(最长公共子序列)

AGTC Description Letxandybe two strings over some finite alphabetA. We would like to transformxintoyallowing only operations given below: Deletion:a letter inxis missing...

weixin_30621919的博客 221

用友U8自定义按钮开发:从基础配置到实战业务集成

本文详细介绍了用友U8自定义按钮开发的完整流程,从基础配置到实战业务集成。通过实际案例演示如何在U8系统中添加和替换功能按钮,包括数据库配置、SQL脚本编写和VB组件开发等关键技术点,帮助企业用户实现业务场景的深度定制。

weixin_29698641的博客 265

Rclone替代RaiDrive?零广告免费挂载Alist WebDAV到Windows资源管理器(含自启脚本)

本文详细介绍了如何使用开源工具Rclone替代RaiDrive,实现零广告、全免费的Alist WebDAV挂载方案。通过深入解析配置参数、提供完整的自启动解决方案和解决常见问题,帮助用户在Windows资源管理器中高效管理云存储,提升使用体验。

weixin_33709364的博客 646

pku 3356 AGTC

AGTC Time Limit:1000MS  Memory Limit:65536KTotal Submit:1285 Accepted:395Description Input Output Sample Input Sample Output4#include iostream>#include string>using namespace std

liyanguestc的专栏 1005

Python爬虫实战:5分钟搞定东方财富网股票数据抓取(附完整代码)

本文详细介绍了如何使用Python爬虫快速抓取东方财富网的股票数据,包括环境配置、API分析、核心代码实现及优化技巧。通过简单的requests和pandas库,5分钟内即可获取高质量股票数据,适合量化交易和数据分析初学者。

weixin_29040367的博客 1197

poj 3356

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

weixin_34273479的博客 156

拥有AI助手便能解放双手?——抖音直播脚本的生成

科技改变生活,AI助手帮你完成抖音创作!

Scientist_的博客 2357

静态编译Qt5源码(Kylin-Desktop-V10-SP1-2203-LoongArch64+qt5.15.16)

之前的文档,记录的是通用情况,本次笔者记录下Qt5的静态编译过程,供有需要的小伙伴参考使用的操作系统是Kylin-Desktop-V10-SP1-General-Release-2203-LoongArch64,处理器是龙芯3A5000,架构是loongarch。

aggs1990的专栏 1405

POJ 3356 AGTC(经典DP Edit Distance)

题意:给出2个字符串x, y,长度为n,m,允许使用3种操作,求把x变成y需要的最小步骤,也就是要求两个字符串的编辑距离. 插入:在x的任意位置插入一个字符. 删除:在x的任意位置删除一个字符. 替换:在x的任意位置替换一个字符成任意字符. 设dp[i][j]为x后缀[i:]变成y的后缀[j:]所需要的最小步骤([i:]代表从i位置开始一直到尾部的字符串) 则: 如果x[i] == y

蚂蚁大战大象 941

【DRAM存储器二】Sense Amplifier

详述DRAM颗粒中感应放大器功能、电路结构、工作原理和操作波形

highman110的博客 7224

POJ3356--AGTC(edit distance)动态规划

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 cor

SCUT_Pein 709

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

[poj3356]字符串dp..2014.8.11

/* * dp[i][j]:str1的前i个构成的串变成str2前j个构成的串需要的最少步数 * dp[i][j] = min{ * dp[i-1][j-1]+(str1[i]==str2[j]?0:1) -> 改变 * dp[i-1][j] + 1 -> 删除str1第i个字符 * dp[i][j-1] + 1 -> 添加str2第j个字符到str1的第i个位置 *

When you go away 759

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

POJ3356- AGTC(dp)

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

weixin_43880485的博客 349

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

POJ 3356

都是最长公共子序列。。。。水题,前面的代码就没呢改,加了一个变量就过了,不解释 Source CodeProblem: 3356 User: XXXMemory: 172K Time: 16MS Language: C++ Result: Accepted Source Code #include <stdio.h>#include <string.h>int ...

weixin_30632883的博客 174

【POJ 3356】AGTC

Letxandybe two strings over some finite alphabetA. We would like to transformxintoyallowing only operations given below: Deletion:a letter inxis missing inyat a corresponding posit...

词庸 412

poj3356 AGTC dp把一个字符串经过最少步数转为另一个字符串

AGTC Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7371   Accepted: 2931 Description Let x and y be two strings over some finite alphabet A. We would like

Shirley 4199

动态规划——AGTC

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 positi

LSC_333的博客 513

ACM 动态规划 编辑距离

很久没有更博了..刚开学忙得飞起0..0 最近刷题发现自己有意逃避算法题,很生气啊自己居然潜意识逃避了... 所以今天很认真的写个动态规划! 虽然这是最简单的动态规划... TOJ 1072:编辑距离   描述 假设字符串的基本操作仅为:删除一个字符、插入一个字符和将一个字符修改成另一个字符这三种操作。 我们把进行了一次上述三种操作的任意一种操作称为进行了一步字符基本操作。 下面我们...

请赐教 1359

poj 3356 AGTC 经典动态规划题

详细讲解可见 挑战编程 11.2编辑距离所讲解的,非常充分完整。

小留家心的爱心之窝 ^_^ 678

poj3356---AGTC

http://poj.org/problem?id=3356 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 lette

WILL的专栏 736

动态规划之编辑距离(Edit Distance)

原文地址:Dynamic Programming | Set 5 (Edit Distance) 已知两个字符串str1与str2,str1可以用下面的操作。得到最小的编辑数使得str1转变为str2。 a)insert b)remove c)replace 以上所有的操作成本是一样的。例子:Input: str1 = "geek", str2 = "gesek" Output: 1

K.Sun 2110

POJ-3356

//题意:给你两个字符串,叫你求出最少操作次数,使两个字符串相同; //思路:找出字符串中最长公共子串,用max(Len1,Len2)-dp[Len1][Len2]求最长公共子串:if(a[i-1]==a[j-1],dp[i][j]=dp[i-1][j-1]+1;else dp[i][j]=max(dp[i-1][j],dp[i][j-1]); AC代码: #include #inc

小马的博客 414

POJ--3356:AGTC (DP求最长公共子序列)

1. 文章源地址:http://poj.org/problem?id=3356 2. 解题思路: 2. 解题代码: //POJ--3356:AGTC DP求最长公共子序列 #include #include #include #include using namespace std; char a[1010],b[1010]; int dp[1010][1010]; int ma

酒酿小圆子呀~ 1082
上一篇: POJ 2480 Longge's problem 解题报告(欧拉函数 + 积性函数)
下一篇: Codeforces Round #243 (Div. 2) C. Sereja and Swaps 解题报告
SF-_-
博客等级 码龄15年 28粉丝 227原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值