POJ 3356 AGTC LCS变形题

pku acm 3356 AGTC Java代码 pku acm 第3356题 AGTC Java代码,有详细的注释,动态规划 立即下载


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
#include<iostream>
#include <cstring>
#include<algorithm>
#include <cstdio>
#include <map>
#include <string>
using namespace std;
const int maxn=1000+10;
int dp[maxn][maxn];
int min3(int a,int b,int c)
{
	a=min(a,b);
	a=min(a,c);
	return a;
}
int main()
{
	int len1,len2;
	while(scanf("%d",&len1)!=EOF)
	{
		char s1[maxn];
		char s2[maxn];
		scanf("%s",s1);
		scanf("%d",&len2);
		scanf("%s",s2);
		memset(dp,0,sizeof(dp));
		for(int i=1;i<=len1;i++)
		{
			dp[i][0]=dp[i-1][0]+1;
		}
		for(int i=1;i<=len2;i++)
		{
			dp[0][i]=dp[0][i-1]+1;
		}
		dp[0][0]=0;
		for(int i=1;i<=len1;i++)
		{
			for(int j=1;j<=len2;j++)
			{
				dp[i][j]=min3(dp[i-1][j-1]+((s1[i-1]==s2[j-1])?0:1),dp[i][j-1]+1,dp[i-1][j]+1);
			}
		}
		printf("%d\n",dp[len1][len2]);
	}
	return 0;
}

AD9371 官方例程构建及单音信号收发 项目构建基本流程和AD9361差不多,由于官方使用的ZCU102,记录下移植遇到的一些问题最终接收到正确的正弦波Errors: 0Errors: 0Errors: 0Errors: 0AD9361。 阅读详情

相关推荐

Python+OpenCV实现游戏自动刷怪脚本(附完整代码)

本文详细介绍了如何使用Python和OpenCV开发游戏自动刷怪脚本,涵盖环境搭建、图像识别、行为决策引擎及反检测优化等关键技术。通过完整的代码示例,帮助开发者实现从简单脚本到智能自动化系统的升级,提升游戏效率。

weixin_29032489的博客 521

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的专栏 1422

行车记录仪 - 碰撞检测

功能需求 行车记录仪的核心功能是记录,大部分时候,行车记录仪都是在循环录制视频和音频,而设备的存储空间是有限的,因此录制机制一般是循环覆盖录制,如此一些重要的记录(例如:发生碰撞时的记录)就可能会被覆盖,为了避免这种情况的发生,行车记录仪设备就需要感知这些情况并做特殊处理(例如:备份相应时刻的录像数据)。 实现原理 碰撞检测是通过物理芯片G-sensor来实现的,加速度发生变化时G-sensor驱动会将加速度上报给应用层,应用层做相应处理。 G-sensor G-sensor(Gravity se

qazw9600的专栏 5217

AGTC (P3356)

状态 dp[i][j]代表字符串前i个和j个的最小操作数。注意边界条件。 #include #include #include #include #include #include #include #include #include #include #include using namespace std; //freopen("C://i.txt","r",stdin); #

jiangjiashi的博客 514

超级超级细的CLIP官方模型解读及代码逐行讲解

本文详细解析了OpenAI开源的CLIP模型代码架构。文章首先介绍模型概念,包括训练时通过对称损失计算图像-文本相似度,预测时通过余弦相似度匹配最佳文本。随后重点解析各模块代码实现:LayerNorm改进、QuickGELU激活函数、Transformer编码器结构、ViT图像编码器的特征提取过程、文本编码器的掩码机制和特征投影。最后阐述CLIP整体架构如何整合视觉和文本编码器,并详细说明了特征归一化和相似度计算的关键实现。全文通过代码级解读帮助读者深入理解CLIP模型的实现细节。

m0_64595440的博客 2428

FreeRTOS实战:STM32CubeMX配置USART+DMA实现高效串口通信(附完整代码)

本文详细介绍了如何使用FreeRTOS和STM32CubeMX配置USART与DMA实现高效串口通信。通过对比轮询、中断和DMA三种模式的性能差异,提供完整的STM32CubeMX配置步骤和代码实现,帮助开发者优化嵌入式系统的串口通信性能,显著提升数据吞吐量和系统响应速度。

weixin_29190169的博客 456

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

Nacos2.X 源码分析:为订阅方推送、服务健康检查、集群数据同步、grpc客户端服务端初始化

而Nacos2.X 从http请求改为了grpc请求的方式了,在健康检查这方面就是基于长连接来实现的。客户端发送心跳是在构建grpc连接时会有一个线程每隔5s发送一次,NacosClient端发送心跳的代码在。我们能大致猜测:当一个服务的实例进行了更新,那么是不是应该推送给所有订阅了该服务的客户端?当我订阅了某个服务,是不是应该将该服务信息推送给我?在服务实例检查检查流程中,如果出现了要注销的服务实例就会发布。在服务发现时,进行订阅服务的最后会发布一个。服务注册与服务订阅流程中发布的事件最终会被。

qq_44027353的博客 1594

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

基于激光雷达与视觉融合的四旋翼无人机室内避障方法研究

本文研究了一种基于激光雷达与视觉融合的四旋翼无人机室内避障方法。针对单一传感器在室内环境中的局限性,提出通过激光雷达提供精确几何距离、视觉相机补充语义信息的融合方案。研究内容包括:搭建ROS硬件平台集成单目相机与2D激光雷达;设计基于扩展卡尔曼滤波的传感器融合模型;改进VFH算法结合视觉深度图进行路径规划。实验验证表明,该方法在复杂室内环境下具有较高的鲁棒性、实时性与避障成功率,为解决无GPS信号环境下的无人机自主导航问题提供了有效方案。

huanghm88的专栏 348

(四)DDR协议命令波形时序一——(ACT、Read、Write)

文章目录一、DDR命令真值表二、ACT激活命令时序要求2.1、ACTIVATE波形——tRRD、tFAW2.2、ACTIVATE波形——tRAS、tRC三、Read命令时序要求3.1、Read 波形——无Additive Latency3.2、Read 波形——有Additive Latency3.3、Read 波形——Additive Latency使用场景 一、DDR命令真值表 DDR的Command命令由CKE、CS#、RAS#、CAS#、WE#信号组成,这几个信号进行不同的搭配组合会形成不同的Co

Mr.翟的博客 6873

AGTC POJ - 3356(字符串DP)

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

tomjobs的博客 889

效果炸裂_安装midscene_copw基于midscene操作电脑_基于视觉的软件测试执行_MIDSCENE的安装和使用---AI大模型应用探索0012

摘要:本文介绍了如何通过安装MidSceneJS来增强Copaw的屏幕操作能力。首先需要安装Node.js和npm,并配置淘宝镜像源加速安装。然后全局安装MidScene CLI工具(npm install @midscene/cli -g)。接着配置视觉大模型服务,通过设置环境变量指定模型API密钥、名称、基础URL和家族类型(如qwen3.5-27b),配置文件需存放在C:\Users\Administrator.copaw目录。安装成功后,MidScene已能成功识别并操作屏幕,使用效果良好。文中还提

添柴程序猿的专栏 641

poj 3356 AGTC(lcs 变形题)

1、http://poj.org/problem?id=3356 2、题目大意: 给定两个字符串,目的是将第一串转换成和第二串相同的字符串,可以有三种操作,1、可以有增加、删除和改变的操作,删除即如果y中有,x没有,则在同位置y中可以删去,改变是指,x中的字符可以改成跟Y中的字符一样的,求得是最少几步可以将x字符串转换成y字符串    此题类似于求最长公共子序列,状态转移方程为

sdjzping的专栏 1007

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

poj 3356 AGTC

/* Name: poj 3356 AGTC Author: UnimenSun Date: 17/05/2011 16:25 Description: LCS变形*//*解题报告:LCS的变形要求结果 = 串2的长度 - 两串的LCS*/#include #include #include #include using namesp

Unimen的专栏 442

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

LCS变形题

1、http://poj.org/problem?id=3356 2、题目大意: 给定两个字符串,目的是将第一串转换成和第二串相同的字符串,可以有三种操作,1、可以有增加、删除和改变的操作,删除即如果y中有,x没有,则在同位置y中可以删去,改变是指,x中的字符可以改成跟Y中的字符一样的,求得是最少几步可以将x字符串转换成y字符串    此题类似于求最长公共子序列,状态转移方程为      

chx 676

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

实验5 动态规划实验一

OJ练习 1. Multiplication Puzzle:http://poj.org/problem?id=1651 2. 【该题可以转化为矩阵连乘问题】 3. Common Subsequence:http://poj.org/problem?id=1458 4. 【该题只需要输出最长公共子序列的长度】 3*. Human Gene Functions:Human Gene...

Roni 1387

pojAGTC(LCS,DP)

题目链接: 啊哈哈,点我点我 题意:给两个字符串,找出经过多少个操作可以使得两个串相等。。 思路:找出两个串的最长公共子序列,然后用最大的串的长度减去最长公共子序列的长度得到的就是需要的操作数。。 题目: AGTC Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1001

大洋深处 852

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 at a co

我不坚强谁替我勇敢 1110

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测试数据合集

本文部分链接可能已失效 测试数据仅供参考学习之用 希望各位同学不要用来刷题 ====================================   1、USACO 2006年November题目和测试数据的网址 http://ace.delos.com/NOV06 2007年open赛题目和测试数据的网址 http://ace.delos

一苇以航 3012

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 posit

BeanBangbang的博客 475

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的专栏 1004

POJ——3356 ACGT

题意: 给定原zifu

时有限 626

POJ原题测试数据合集+使用方法

原文地址:POJ测试数据合集 可以在疯狂WA的时候检测卡在哪里了,非常方便(网站加载很慢,但是应该不用科学上网) 使用方法 在poj的题目下,有来源的话会注明来源,例如poj-1753 Source Northeastern Europe 2000 可以看出是东北部欧洲2000年的题目,那么在下面的连接中寻找Northeaster

iwts 1万+
上一篇: POJ 1080 Human Gene Functions LCS变形题
下一篇: POJ 3624 Charm Bracelet 01背包
UntilTheEnd
博客等级 码龄12年 0粉丝 36原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值