HDU1841 Find the Shortest Common Superstring(两次KMP)

『杭电1841』Find the Shortest Common Superstring Problem Description The shortest common superstring of 2 strings S1and S2is a string S with the minimum number of characters which contains both S1and S2as a sequence of consecutive characters. For instance, the shortest common superstring of “alba” ... 阅读详情

链接:

http://acm.hdu.edu.cn/showproblem.php?pid=1841

题意:

两个字符串拼接,问拼成新串的最小长度,使得新串包含两个原串。

思路:

跑两遍kmp,找最长前缀。(先排除包含情况)

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6+10;
int next[maxn];
void getnext(char *b)
{
    int len = strlen(b+1);
    memset(next,0,sizeof next);
    int j=0;
    for(int i=2;i<=len;i++)
    {
        while(j&&b[j+1]!=b[i]) j=next[j];
        if(b[j+1]==b[i]) j++;
        next[i]=j;
    }
}
int kmp(char *a,char *b)
{
    int l1=strlen(a+1),l2=strlen(b+1);
    getnext(b);
    int j=0;
    for(int i=1;i<=l1;i++)
    {
         while(j&&b[j+1]!=a[i])j=next[j];
         if(b[j+1]==a[i])j++;
         if(j==l2) return -1;
    }
    return j;
}
int main()
{
    int  t;
    cin>>t;
    while(t--)
    {
        char s1[maxn],s2[maxn];
        scanf("%s%s",s1+1,s2+1);
        int r=kmp(s1,s2);
        int l=kmp(s2,s1);
        if(r==-1||l==-1)
            cout<<max(strlen(s1+1),strlen(s2+1))<<endl;
        else
            cout<<strlen(s1+1)+strlen(s2+1)-max(r,l)<<endl;
    }
    return 0;
}

 

从代码层面分析STM32 标准库和HAL库的差异 相当于每个设置都是独立的函数。HAL库将一段代码通过宏定义的方式封装成了一个函数,每个端口的时钟都单独的定义了一个名称,标准库是一个独立的函数,通过参数传递的方式来设置每个端口的时钟。这两个版本的函数本质上操作的还是寄存器,不过HAL库操作的只是BSRR寄存器,而标准库端口置1的时候操作的是BSRR寄存器,端口清0的时候操作的是BRR寄存器。标准库设置端口模式的时候,是在if语句中判断之后直接设置的,而HAL端口模式设置时,却使用了switch语句去设置,说明在HAL库中,端口模式和标准库中发生了改变。 阅读详情

相关推荐

MATPOWER的安装详细教程

MATPOWER的安装包实际为一个程序包,安装教程很简单,详见本文。

半个月亮Zz的博客 3万+

【项目实训日志二】Shortest Superstring最短超串问题

Shortest Superstring最短超串问题问题定义定义overlap贪心算法举例A factor 4 algorithm一个近似比为4的算法具体算法理解算法证明近似比为4引理7.2引理7.3定理7.4证明把近似比优化至3定义压缩具体算法证明近似比为3引理7.6引理7.7 本文章总结一下《Approxiamte Algorithms》一书中第七章Shortest Superstring的相关内容。 问题定义 Given a finite alphabet Σ, and a set of n stri

qq_41910471的博客 1369

探索Vortex开源GPGPU:RISC-V SIMT架构(4-1),Execute SFU(1)

本文详细分析了Vortex RISC-V内核6级流水线中Execute阶段的SFU(特殊功能单元)模块。重点介绍了SFU的数据流结构,包含dispatch_unit、pe_switch、csr_unit、wctl_unit和gather_unit五个子模块。文章深入解析了warp控制指令wspawn和tmc的实现机制:wspawn用于激活指定数量的warp并设置新PC值,tmc则用于控制线程掩码和warp状态。通过C代码和汇编指令的对照分析,阐明了这些指令在并行计算中的关键作用,包括线程激活、状态切换和执行

weixin_55313207的博客 1376

【Leetcode】943. Find the Shortest Superstring

是已经选择的单词的所有下标的集合的二进制压缩(显然同一个单词不会选择超过。的前缀的最长重合的长度(这个长度我们要预处理一下)。中单词各不相同,并且没有一个单词是另一个单词的子串。可以递推出什么样的状态,递推的前提是。次,这样没有意义)。里每个单词都是其子串。),那么长度的增加值实际上是。结尾的情况下所能得到的最短。是已经选择的单词的状态为。再由这个答案倒过来推出。,每个单词长度不超过。为单词最长长度,空间。

数学、算法爱好者的博客 339

BCM-BCP-DRP-运维管理之故障管理——故障的分类与处理流程

ITSM Business Continuity Manage(BCM) BusinessContinuityPlan(BCP) 偏业务 DisasterRecoveryPlan(DRP) 偏IT 天塌了,考虑在天塌了的状态下做什么,怎么开展业务就是BCP; 天塌了,考虑怎么把天撑回去,就是DRP。 DRP+BCP+供应链管理+危机管理等就是BCM (业务连续性管...

mmgithub123的博客 2734

深入了解神经网络:构建人工智能的基石

这篇博客将为您解释神经网络的构造,让您能够理解这个令人着迷的领域的基本工作原理。神经网络是人工智能领域的关键技术,它们的构造基于神经元的灵感,并结合了数学、统计和机器学习的原理。输入可以类比为神经元的树突,而输出可以类比为神经元的轴突,计算则可以类比为细胞核。较好的方法就是预先设定几个可选值,通过切换这几个值来看整个模型的预测效果,选择效果最好的值作为最终选择。:这是神经网络的核心部分,包含多个层次的神经元。、神经网络结构图中的拓扑与箭头代表着预测过程时数据的流向,跟训练时的数据流有一定的区别;

AI_dataloads的博客 2万+

leetcode942-Find the Shortest Superstring

这道题目很明显我们可以记录一个最小值和最大值,当s[i] == ‘I’ 的时候perm[i]比perm[i+1]小1,那么perm[i]可以是最小值,perm[i+1]比他大即可。当s[i]=='D’的时候perm[i]可以是最大值,perm[i+1]比他小即可,每遍历完一次就更新这个最小值和最大值,但是这种思路把问题复杂化了,这种思路每遍历一个元素要求同时更新perm[i]和perm[i+1],但是我们怎么能重复更新元素呢,而且也不能确定下一个元素到底是I还是D。输出:[0,4,1,3,2]

我的程序人生 521

MATLAB绘图中文乱码终极解决方案:从方框到清晰显示的全面指南

本文提供了MATLAB绘图中文乱码的全面解决方案。针对中文显示为方框的问题,从单次绘图的临时字体设置,到通过修改默认配置实现一劳永逸,再到系统级字体排查与Java环境配置,给出了详细的步骤指南。文章还涵盖了字体名称指定、图像导出防丢失以及跨平台协作等高级技巧,帮助用户彻底解决中文乱码困扰。

weixin_29093017的博客 623

LeetCode每日一题(943. Find the Shortest Superstring)

看得官方的解法, 不想多说了, 有兴趣的看。

wangjun861205的博客 1383

解忧杂货铺(四):Hightec生成HEX方法+小功能开启

Hightec使用的一些常用技能

梦想技术家 2173

⭐️VMwareWorkstation17.0虚拟机搭建WindowsXP虚拟机(完整安装步骤详细图文教程)

Windows XP是微软公司研发的计算机操作系统,于2001年10月25日正式发布。其名字中“XP”的意思来自英文中的“体验”(Experience)。Windows XP使用了Luna图形用户界面和双列开始菜单,提升了系统的安全性和工作性能,提供了WiFi支持,简化了软件的安装和运行,并增加了远程桌面功能。

Python老吕的博客 1万+

HDU - 1841 Find the Shortest Common Superstring

Find the Shortest Common Superstring The shortest common superstring of 2 strings S 1 and S 2 is a string S with the minimum number of characters which contains both S 1 and S 2 as a sequence of

什么样的小孩 的博客 333

搬运机器人系列编程:KUKA KR QUANTEC_(2).KUKA KRL语言编程基础

定义一个函数END!调用函数PRINT "结果: ", result!定义一个过程PRINT msgEND!调用过程printMessage("欢迎使用 KUKA 机器人")!定义搬运零件的起始位置和目标位置!定义焊接路径的各个点!定义喷涂路径的各个点KUKA Robot Language (KRL) 是一种专门为工业机器人设计的编程语言,具有结构化编程、丰富的库函数、实时性以及集成性等特点。

zhubeibei168的博客 1268

hdu1841 Find the Shortest Common Superstring

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1841 题解:1.s1是s2的子串,或者s2是s1的子串。2.s1是s2的前缀或者后缀。 #include #include #define MAXN 1000002 int next[MAXN]; char str1[MAXN],str2

不可不戒 848

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

Find the Shortest Common Superstring(hdu1841,KMP)

http://acm.hdu.edu.cn/showproblem.php?pid=1841 解析: 题意: 找到一个最短的串s,含有子串s1,s2 思路:两次KMP匹配 求出,s1后缀和s2前缀的最长公共串长度m1,       s2后缀和s1前缀的最长公共串长度m2;       ans=strlen(s1)+strlen(s2)-max(m1,m2); 6096 KB 359

JHC23的专栏 951

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

hdu1841 Find the Shortest Common Superstring-----KMP

Find the Shortest Common Superstring Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 971 Accepted Submission(s): 243 Problem Description T

Shirley 1430

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

hdu1841 Find the Shortest Common Superstring 两遍KMP

hdu1841 Find the Shortest Common Superstring 两遍KMP问题描述 :The shortest common superstring of 2 strings S1 and S2 is a string S with the minimum number of characters which contains both S1 and S2 as a seq

愿赌服输 704

HDU 1841 Find the Shortest Common Superstring KMP

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1841 题意:给你两个字符串,求解一个最短的字符串,两个字符串连接的时候相同的可以重叠 例如: “alba” 和“bacau”重叠在一起的最短串是 “albacau”。 我感觉这道题用KMP,求next数组就行,先将两个字符串连接起来(两种方法),然后求解next[len],当这个

lamborghini1993 1243

hdu 1841 Find the Shortest Common Superstring

hdu 1841 点击打开链接 题意:给出两个字符串s1,s2,找到一个最短的字符串s,似的s1是它的子串,s2也是它的字串。 方法:用KMP,首先判断s1是否是s2的字串,若是,则直接输出s2的长度,,即s2就是我们找的s字符串。同理判断s2是否是s1 的字串。 若都不是,,则判断s1 的前缀与s2的后缀最大重合部分k1,s2的前缀与s1后缀最大重合部分k2,判断k1与k2的大小,

ACM_korun 884

HDU 1841 Find the Shortest Common Superstring(KMP)

Find the Shortest Common Superstring Problem Description The shortest common superstring of 2 strings S1 and S2 is a string S with the minimum number of characters which contains both S1 and S2 as

持之以恒 471

hdu1841Find the Shortest Common Superstring

Find the Shortest Common SuperstringTime Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 2062    Accepted Submission(s): 570Problem DescriptionThe sh...

mayuqing98的博客 428

HDU 1841 Find the Shortest Common Superstring(KMP灵活运用)

ind the Shortest Common Superstring Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 1149    Accepted Submission(s): 289 Problem Descri

布生气 1368

HDU1841 Find the Shortest Common Superstring (KMP两字符串的首尾连接)

题意:给我们两个字符串,求解一个最短的字符串,两个字符串连接的时候相同的可以 重叠,例如:“alba” 和“bacau”重叠在一起的最短串是 “albacau”。 解析:最初看到这题时,是将两个串连接起来,用strcat函数,然后利用kmp求它的 循环子段,这就是我的数组为啥开的两倍,但后来发现对于“abaa”“a”或者“aaaba” “aa”….类似这一类,它的处理就会出错,后来将它分开处

天行健的博客 463

HDU 1841: Find the Shortest Common Superstring

!!!#include #include #include using namespace std; char a[2000005],b[2000005]; int nextd[2000010]; void get(char *ch) { int l = strlen(ch); int s = 0,t = -1; nextd[0] = -1; while(s <l) { if(t

无知的博客 609

HDU 1841 Find the Shortest Common Superstring

戳这里

WSMYE的博客 (hemiaomiao.me) 316

文章标题 HDU 1841:Find the Shortest Common Superstring(KMP)

Find the Shortest Common SuperstringDescriptionThe shortest common superstring of 2 strings S 1 and S 2 is a string S with the minimum number of characters which contains both S 1 and S 2 as a sequence

Wang_SF2015的博客 469
上一篇: Gym - 101550F - Fleecing the Raffle(暴力)
下一篇: 基姆拉尔森计算公式 推导
Healer66
博客等级 码龄9年 331粉丝 267原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值