hdu 1513 Palindrome 回文 LCS 滚动数组

FPGA和USB3.0通信知识记录(1)——基于特权同学图书《Xilinx FPGA伴你玩转USB3.0与LVDS》 大家好,我是一个新人,请多多关照! 我的毕业论文选题和特权同学《Xilinx FPGA伴你玩转USB3.0与LVDS》图书相关,所以在学习这本书的同时,做一下记录。 第一章:FPGA、USB和LVDS概述 1.1~1.4 都在介绍FPGA的发展历史、应用领域和开发流程。 1.5 USB接口概述 (1)发展史:20世纪90年代末,计算机开始集成USB接口。USB1.1最高速度大12Mb/s;USB2.0最高480Mb/s;USB3.0将文件传输速度提升至5Gb/s。而USB取代的是图1“大家伙”. 阅读详情

 求最少补多少个字符使所给字符串变成回文,直接dp,dp[i][j]代表从i到j的字串中最少补的字符。1、如果a[i]==a[j],dp[i][j]=dp[i+1][j-1],不用加新字符的情况;2、如果a[i]!=a[j],dp[i][j]=min(dp[i+1][j],dp[i][j-1])+1,在中间字符串的基础上再补一个字符;n的范围是5000二维会超内存,这里注意每次dp[i][j]的更新都用到dp[i+1]和dp[i][j-1],j-1可以让j为升序,dp[i+1]用滚动数组存,因为每次只用到两层dp(和下标的奇偶性),让i降序,即可使每次计算dp[i][j]时,dp[i+1]和dp[i][j-1]均为已知,dp[2][5000]实现dp过程。


Palindrome

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2084    Accepted Submission(s): 725


Problem Description
A palindrome is a symmetrical string, that is, a string read identically from left to right as well as from right to left. You are to write a program which, given a string, determines the minimal number of characters to be inserted into the string in order to obtain a palindrome. 

As an example, by inserting 2 characters, the string "Ab3bd" can be transformed into a palindrome ("dAb3bAd" or "Adb3bdA"). However, inserting fewer than 2 characters does not produce a palindrome.
 

Input
Your program is to read from standard input. The first line contains one integer: the length of the input string N, 3 <= N <= 5000. The second line contains one string with length N. The string is formed from uppercase letters from 'A' to 'Z', lowercase letters from 'a' to 'z' and digits from '0' to '9'. Uppercase and lowercase letters are to be considered distinct.
 

Output
Your program is to write to standard output. The first line contains one integer, which is the desired minimal number.
 

Sample Input
5 Ab3bd
 

Sample Output
2
 
#include<stdio.h>
#include<string.h>
#define size 5010
int n,dp[2][size];
char a[size];
int min(int a,int b)
{
	return a>b?b:a;
}
int main()
{
	int i,j,k,l,m;
	while(scanf("%d",&n)!=EOF)
	{
		memset(a,0,sizeof(a));
		memset(dp,0,sizeof(dp));
		getchar();
		scanf("%s",&a);
		for(i=n-2;i>=0;i--)
		{
			for(j=i+1;j<n;j++)
			{
				if(a[i]==a[j])
					dp[i%2][j]=dp[(i+1)%2][j-1];
				else
					dp[i%2][j]=min(dp[(i+1)%2][j],dp[i%2][j-1])+1;
			}
		}
		printf("%d\n",dp[0][n-1]);
	}
	return 0;
}

贴一个网上的例子

滚动数组很适合用在二维DP而且是数组在很大时,可以节省内存,消除超内存的隐患!具体思想还是看了网上的资料,转载一个,共同享用吧!
滚动数组 举个简单的例子:
int i,d[100];
d[0]=1;d[1]=1;
for(i=2;i<100;i++)
d[i]=d[i-1]+d[i-2];
printf("%d",d[99]);
上面这个循环d[i]只需要解集中的前2个解d[i-1]和d[i-2];
为了节约空间用滚动数组的方法


int d[3];
d[0]=1;d[1]=1;
for(i=2;i<100;i++)
d[i%3]=d[(i-1)%3]+d[(i-2)%3];
printf("%d",d[99%3]);


注意上面的运算,我们只留了最近的3个解,数组好象在“滚动?一样,所以叫滚动数组


对于二维数组也可以用这种方法 例如:
int i,j,d[100][100];
for(i=1;i<100;i++)
    for(j=0;j<100;j++)
        d[i][j]=d[i-1][j]+d[i][j-1];


上?的d[i][j]忪便赖于d[i-1][j],d[i][j-1];
迿用滚动数组
int i,,j,d[2][100];
for(i=1;i<100;i++)
    for(j=0;j<100;j++)
        d[i%2][j]=d[(i-1)%2][j]+d[i%2][j-1];


滚动数组实际是一种节约空间的办法,时间上没什么优势,多用于DP中,举个例子先: 
一个DP,平常如果需要1000×1000的空间,其实根据DP的特点,能以2×1000的空间解决问题,并且通过滚动,获得和1000×1000一样的效果。










RK3588与FocalTech触摸屏代码适配全解析:从原理到实战 摘要:本文详细介绍了瑞芯微RK3588处理器与FocalTech触摸屏的适配过程,包括硬件特性、驱动加载、设备树配置和常见问题解决方案。RK3588作为8nm工艺的高性能处理器,具备强大的计算能力和丰富的接口资源;FocalTech触摸屏则采用电容式技术,支持I2C/SPI接口。适配关键步骤包括驱动程序加载、硬件连接检查、设备树配置和内核版本兼容性处理,并提供了代码示例和问题排查方法。随着嵌入式设备智能化发展,该适配技术将持续优化,为智能交互提供更优解决方案。 阅读详情

相关推荐

Qt5.15.2安卓开发环境配置保姆级教程(含JDK8、SDK33、NDK21.4及Gradle国内镜像避坑指南)

本文提供Qt5.15.2安卓开发环境配置的完整教程,涵盖JDK8、SDK33、NDK21.4及Gradle国内镜像设置,帮助开发者快速搭建开发环境并避免常见问题。通过详细步骤和实战技巧,解决依赖冲突、网络超时等难题,提升开发效率。

weixin_28730353的博客 209

hdu1513Palindrome回文数【LCS】【滚动数组】

Palindrome Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 73   Accepted Submission(s) : 20 Problem Description A palindrome is a symmetrica

qingkong5886的博客 413

Goose开源程序本地机上 AI 代理,能够从头到尾自动执行复杂的开发任务。Goose 不仅可以提供代码建议,还可以自主构建整个项目、编写和执行代码、调试故障、编排工作流程以及与外部 API 交互

Goose开源程序 是您的本机上 AI 代理,能够从头到尾自动执行复杂的开发任务。Goose 不仅可以提供代码建议,还可以自主构建整个项目、编写和执行代码、调试故障、编排工作流程以及与外部 API 交互。无论您是在构建想法原型、优化现有代码,还是管理复杂的工程管道,goose 都能适应您的工作流程并精确执行任务。

struggle2025的博客 2060

hdu 1513 Palindrome【LCS滚动数组】

链接: http://acm.hdu.edu.cn/showproblem.php?pid=1513 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=28195#problem/B Palindrome Time Limit: 4000/2000 MS (Java/Others)    Memory

free斩 1462

A算法的蒙特卡洛树搜索

A*算法的蒙特卡洛树搜索 作者:禅与计算机程序设计艺术 1. 背景介绍 在人工智能和游戏开发领域,搜索算法是一个非常重要的研究方向。其中A算法和蒙特卡洛树搜索是两种广泛应用的经典算法。A算法是一种启发式搜索算法,通过评估各个节点到目标节点的启发式代价来引导搜索方向,在

AI天才研究院 1849

电子元器件-逻辑器件篇:逻辑电平、CMOS逻辑、手册解读、逻辑电平转换,应用注意事项

常用的逻辑电平TTL、CMOS、LVTTL、LVCOMS、CML、ECL、PECL、LVPECL、LVDS、RS232电平RS422电平,RS485电平等。TTL和CMOS的逻辑电平按典型电压可分为四类:5V系列、3.3V系列,2.5V系列和1.8V系列。5V TTL和5V CMOS逻辑电平是通用的逻辑电平。3.3V及以下的逻辑电平被称为低电压逻辑电平,常用的为LVTTL电平低电压的逻辑电平还有2.5V和1.8V两种。

qq_60226558的博客 871

HDU 1513 Palindrome【LCS+滚动数组】

Palindrome Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3423    Accepted Submission(s): 1181 Problem Description A palindrome is a s

_阿阿阿阿欢 443

人工智能训练师三级·模型生命周期真题40题|训练→评估→调优全链路通关

本文为人工智能训练师三级考试真题解析系列第2篇,聚焦模型生命周期全链路(训练→评估→调优)。内容包含40道精选真题,覆盖数据划分、模型训练、评估指标、超参数调优4个核心阶段。重点考察:1)数据集的合理划分方法(留出法、交叉验证);2)模型训练的基本原理;3)关键评估指标(准确率、召回率、F1等)的应用场景;4)超参数调优技术(网格搜索、随机搜索等)。通过真题解析帮助考生系统掌握模型生命周期的闭环迭代方法论,提升从数据准备到模型优化的全流程实践能力。适合备考人工智能训练师三级认证的考生学习参考。

白话机器学习 105

HDU1513 Palindrome(LCS+滚动数组)

PalindromeTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4960 Accepted Submission(s): 1703Problem Description A palindrome is a symmetrica

MrBlank的ACM记事本 339

AUTOSAR 导入DBC ISOLAR工程配置

ISOLAR工程配置-dbc导入

汽车电子电气 2419

YOLO26改进策略【模型轻量化】| 替换骨干网络为 2024轻量化网络MoblieNetV4:移动生态系统的通用模型

本文记录的是基于MobileNet V4的YOLO26目标检测轻量化改进方法研究。主要用于轻量化应用部署,相关轻量化改进与其整体架构非常适配。通过整合、以及优化的,能够在在不降低性能指标的前提下,降低计算成本。本文配置了原论文中、、、和五种模型,以满足不同的需求。MobileNetV4: Universal Models for the Mobile Ecosystem是一系列适用于移动生态系统的通用高效模型。以下将详细介绍其轻量化设计的出发点、原理、结构和优势:的实现代码如下: 四、修改步骤 4.1 修

Limiiiing的博客 872

HDU-1513 Palindrome 【LCS+滚动数组】

PalindromeTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5241 Accepted Submission(s): 1796Problem Description A palindrome is a symmetrica

DTL66的博客 367

Python爬虫实战:如何爬取京东商品评论数据

在本文中,我们介绍了如何使用 Python 爬虫技术爬取京东商品的评论数据。首先,我们分析了京东商品评论的 API 接口和 JSON 数据结构,然后编写了爬虫程序来抓取评论数据,并将数据保存到 CSV 文件中。接着,我们进行了一些基本的数据分析,包括评分分布和简单的情感分析。爬取京东商品评论的数据可以为电商分析、情感分析等提供有价值的信息。你可以在此基础上进行更深入的分析,挖掘更多的商业价值。希望本篇教程能够帮助你了解如何利用 Python 进行电商数据的爬取和分析!

2201_76125261的博客 1674

Palindrome HDU - 1513(LCS 滚动数组)

Palindrome HDU - 1513题意:给出一个字符串, 要求插入最少的字符使得该串成为回文串;对给出串和它的反转串求一遍LCS, 串的长度减去LCS就是答案;注意要用滚动数组, 否则会超内存;#include &lt;cstdio&...

Sirius_han的博客 222

精雕软件(JDpaint) 5.5 绿色版

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

深度学习工具包 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")

【HDU】-1513-Palindrome(LCS,模板+滚动数组)

Palindrome Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5237    Accepted Submission(s): 1793 Problem Description A palindrome is

Bear1998的博客 443

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

HDU1513 && POJ1159:Palindrome(LCS)

Problem Description A palindrome is a symmetrical string, that is, a string read identically from left to right as well as from right to left. You are to write a program which, given a string, determ

ACM!荣耀之路! 2996

Hdu oj 1513 Palindrome

题目:点击打开链接 分析:LCS+滚动数组 字符串长度—LCS==需要增加的字符个数 滚动数组:优化空间,压缩存储,主要用于递推或动态规划中。 #include #include #define max(a,b) (a>b?a:b) char str1[5010],str2[5010]; int dp[2][5015];//!!!动态数组 int main() { int

zm_11的博客 513

HDU 1513 Palindrome (滚动数组lcs,水)

雷火盘古校园招聘开始! Palindrome Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6427    Accepted Submission(s): 2123 Problem Descrip

K键盘里的青春K 462

HDU 1513 Palindrome:LCS(最长公共子序列)or 记忆化搜索

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1513 题意:   给你一个字符串s,你可以在s中的任意位置添加任意字符,问你将s变成一个回文串最少需要添加字符的个数。 题解1(LCS):   很神奇的做法。   先求s和s的反串的LCS,也就是原串中已经满足回文性质的字符个数。   然后要变成回文串的话,只需要为剩下的每...

a1392136的博客 221

1513 hdu Palindrome 滚动数组+LCS

点击打开题目链接 由于单纯地求LCS会使得运行超时,因此需要想办法减少开支; 可以想到0-1背包问题是如何由二维减少到一维的,事实上,我们最后只需要计算的最后几个解,因此没有必要把每一步计算结果都储存起来,所以选用滚动数组来做; 最后求的dp[n%2][n]lcs长度,n - dp[n%2][n]即为所求: #include&lt;iostream&gt; #include&lt;cst...

Abner 808

hdu1513Palindrome【最长公共子序列&滚动数组】

问加几个字符能变成回文串==赤裸裸的LCS 而且都不用记录路径 /************ hdu1513 2016.2.12 483MS 1616K 975 B G++ ************/ #include #include #include using namespace std; int c[2][5005],n,sum; char x[5005],y[5005]; void

MissZhou要努力 680

hdu_1513_Palindrome(LCS+滚动数组)

题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1513 题意:给你一个字符串,问你最少插入多少个字符使其为回文字符。 题解:将字符串倒着保存,然后求一下原串和该串的最长公共子序列,然后字符串长度剪LCS就是答案 #include #define FFC(i,a,b) for(int i=a;i<=b;i++) int n,dp[2][5010]

bin_gege的博客 238

HDU 1513[Palindrome] 回文串

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1513 题目大意:给一个字符串,问最少加多少个字母能成为回文串。 关键思想:要解决的是回文子序列问题而不是回文子串。回文子序列怎么求?可以把字符串倒转一下,再求他们的最长公共子序列啊!想一想为什么。求出LCS长度之后,n-LCS才是我们要的答案,因为对于不是回文子序列的其他字符来说,都需要给他们一个...

weixin_30576859的博客 93

POJ 1159 && HDU 1513 Palindrome(LCS)

Description 给你一个字符串,可在任意位置添加字符,最少再添加几个字符,可以使这个字符串成为回文字符串 Input 第一行一个整数n表示字符串长度(n Output 输出能使原字符串变为回文字符串最少需要添加几个字符 Sample Input 5 Ab3bd Sample Output 2 Solution 设原序列S的逆序列为S’,则最少需要补充的字母数=原序列S

ZSQ 624

hdu1513&&poj 1159 Palindrome(LCS+滚动数组)

Palindrome Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 50914   Accepted: 17537 Description A palindrome is a symmetrical string, that is, a string read

Coding A World 923

HDU-1513 Palindrome LCS+滚动数组

http://acm.hdu.edu.cn/showproblem.php?pid=1513 将原字符串倒置,然后与原字符串求最长公共子序列,     答案就是len-dp[len][len]。 #include "stdio.h" #include "string.h" const int maxn = 510; int n; char str1[maxn],str2[maxn

菜鸟成长ing 504

HDU 1513 Palindrome(DP)

水题。 倒置字符串求LCS。 数据略大,需要用滚动数组。 #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; #def

ACMiao的博客 398
上一篇: 超级玛丽跳 时间的优化
下一篇: hdu 2686 Matrix 双线程dp
yan_____
博客等级 码龄14年 22粉丝 93原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址