杭电-1238Substrings(爆搜)

『杭电1238』Substrings Problem Description You are given a number of case-sensitive strings of alphabetic characters, find the largest string X, such that either X, or its inverse can be found as a substring of any of the given strings. Input The first line of the input fi 阅读详情

Substrings

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8626    Accepted Submission(s): 4001


Problem Description
You are given a number of case-sensitive strings of alphabetic characters, find the largest string X, such that either X, or its inverse can be found as a substring of any of the given strings.
 

Input
The first line of the input file contains a single integer t (1 <= t <= 10), the number of test cases, followed by the input data for each test case. The first line of each test case contains a single integer n (1 <= n <= 100), the number of given strings, followed by n lines, each representing one string of minimum length 1 and maximum length 100. There is no extra white space before and after a string.
 

Output
There should be one line per test case containing the length of the largest string found.
 

Sample Input
2 3 ABCD BCDFF BRCD 2 rose orchid
 

Sample Output
2 2
 

猛地一看还以为是LCS,原来是个爆搜题!不会超时放心枚举!

找出最短的串,然后枚举这个串的所有子串和反串即可!




#include<cstdio>
#include<cstring>
#include<aLgorithm>
#define INF 0x3f3f3f3f
char map[110][110],s1[110],s2[110];
int main()
{
	int N,k,i,j,m,n,ma,f,MAX;
	scanf("%d",&N);
	while(N--)
	{
		scanf("%d",&n);
		ma=INF;
		for(i=0;i<n;i++)
		{
			scanf("%s",map[i]);
			int len=strlen(map[i]);
			if(len<ma)
			{
				ma=len;
				f=i;
			}
		}
		MAX=0;
		int flag=1;
		for(i=0;i<ma;i++)
		{
			for(j=i;j<ma;j++)
			{
				for(k=i;k<=j;k++)
				{
					s1[k-i]=map[f][k];//正子串
					s2[j-k]=map[f][k];//反子串
				}
				s1[j-i+1]=s2[j-i+1]='\0';
				
				int len3=strlen(s1);
				for(k=0;k<n;k++)
				{
					if(!strstr(map[k],s1)&&!strstr(map[k],s2))//子串都没出现过
					{
						flag=0;
						break;
					}
				}
				if(len3>MAX&&flag)
				MAX=len3;
				flag=1;
			}
		}
		printf("%d\n",MAX);
	}
	return 0;
}





组态王7.5和SQLsever数据库交互 摘要:本文详细介绍了组态王7.5与SQL Server 2016数据库交互的实现流程,包括建立连接、数据存储与查询操作。主要内容涵盖ODBC数据源配置、数据库表格创建、数据插入及查询功能实现(含日期控件查询) 阅读详情

相关推荐

伺服电机开发实战指南

伺服电机作为工业自动化的核心部件,正经历前所未有的技术革新。本文从基础原理出发,详细介绍了伺服电机的分类、工作原理和特性,分析了伺服电机系统组成与核心部件,探讨了企业级开发技术,包括控制算法、通信协议和故障诊断等高级功能,并提供了实战案例分析,从行业应用到具体开发步骤,展示了伺服电机的工程实现。通过深入理解伺服电机的原理、掌握开发技术、学习应用案例,可以实现伺服系统的高性能开发与应用。

全栈 1676

substrings(子串)

题意:给定n个字符串,求每个字符串中都出现过的(正串反串都可以),长度最大的子串。链接: http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?pid=1000&ojid=0&cid=10646&hide=0思路: 找到长度最小的那个字符串,三重循环,第一重是限定子串开始的位置,第二重是限定子串的长度,第三重分别是复制两个子串和判定子串

cpfor 1815

python数据分析与可视化

Python数据分析主要包括数据清洗、数据探索和数据可视化三个部分。数据清洗是数据分析的重要环节,主要是对数据进行预处理,包括缺失值处理、异常值处理、数据类型转换等。数据探索则是通过对数据进行初步分析,了解数据的分布和特征,为后续的数据分析提供基础。数据可视化则是将数据以图形化的方式呈现,帮助人们更好地理解和分析数据。

2301_82032652的博客 7711

杭电ACM——substrings(搜索)

本题应学会如何将字符串的子串全部罗列出来。要设置三重循坏(仅限数据小的情况) #include&amp;lt;stdio.h&amp;gt; #include&amp;lt;string.h&amp;gt; int main() { int t,n; int i,j,k,l,flag; //i,j,k控制循坏,flag标识 int len,min,max,p=0; //找出所有字...

shamansi99的博客 418

MAX30102心率血样模块在STM32F103芯片的程序说明

我希望你已经安装好了Keil MDK5这个软件,也安装了M3内核,可以编译一些STM32F103的一些项目下载程序后步骤: 1-按照下图找到IIC.uvprojx并打开(途中唯一绿色那个图标) 2-编译一次 3-确保0错误,0警告,下图所示 4-点击目标选项,然后找到STM32F103C8,再点debug–CMSIS****(我实际用的JTAG,用不了,选择这个CMSIS****即可)下图所示 5-下图所示,看看你的串口找到了没,找到了就点左下角的OK 6-按图上传到开发板 7-MAX30102接线方法

weixin_51357422的博客 5801

lammps教程:官方自带eam_database程序拟合EAM势方法介绍

使用lammps模拟金属体系,最常用的势函数为eam、meam势。 对于大多数金属或者合金来说,可以从网上下载相对应的eam或meam势力场文件。 而对于一些新的合金材料,可能就找不到相对应的力场文件。 解决的方法有两种,一是采用混合势(pair_style hybrid),第二种方法是自己拟合势函数文件。 混合势的写法在前面文章中已经介绍过,本文介绍一种拟合EAM势的方法。 该方法是运行Xiaowang Zhou编写的一个拟合程序,该程序可自动生成所需要的合金势。 这个程序能够拟合的合金元素有: Cu,

lammps_jiayou的博客 4613

Swift 中 Substrings 与 String

原作者 Greg Heo (@gregheo) | Twitter ,原文链接:Swift Substrings 为文本字符串添加特性或者语法糖在各种编程语言中都很普遍。就拿大家都很熟悉的 C 语言举例,C 字符串本质是一个字符数组(characters array),但是每次输入字符串的时候不用输入 ['h','e','l','l','o'] ,直接打 hello 就可以了,因为这个操作编译...

weixin_33884611的博客 276

Python赋能,洞见先机:构建基于异步爬虫与流处理的实时舆情监控系统

我们将从核心概念入手,逐步搭建一个集。.option("es.resource", "public-opinion-%s" % time.strftime("%Y-%m-%d")) \ # 按日期分索引。| 数据采集层 |----->| 消息队列层 |----->| 流处理与分析层 |----->| 存储与可视化层 |:使用Spark Streaming的状态操作或Flink的CEP库,检测更复杂的模式,如“某关键词的负面舆情在1小时内激增500%”。

2201_76125261的博客 434

后缀自动机——Substrings

题解: 让我们找长度为x的子串出现的最大次数。我们先建立sam,然后把节点top序。我们知道endpos是一些出现相同次数和相同结束位置的集合。所以我们定义fif_ifi​为长度为i的子串出现的最大次数。我们因为知道长度fi>=fjf_i>=f_jfi​>=fj​,i<ji<ji<j的时候,所以我们只需要更新f[len[i]]f[len[i]]f[len[i]]就可以了。f[len[i]]=max(endpos[i],f[len[i]])f[len[i]]=max(end

行走天涯的豆沙包的博客 318

YOLO系列专栏(六):YOLO26热力图可视化 | 解析模型推理逻辑,定位检测关键区域

YOLO26作为新一代目标检测模型,其核心优势是高效的特征提取和精准的目标定位,但模型内部的推理过程的“黑盒”特性,给我们的优化带来了很大困扰:❌ 检测精度低:不知道是模型没学到关键特征,还是特征提取不充分;❌ 出现误检/漏检:无法定位问题根源——是锚框不合适?还是特征图未捕捉到目标?❌ 模型优化盲目:调参、修改网络结构全靠“猜”,缺乏针对性;❌ 难以解释模型行为:实际项目中,需要说明模型“为什么检测到这个目标”,尤其是医疗、工业等对可解释性要求高的场景。而热力图可视化。

qq_36130719的博客 732

8、 使用TPM密钥:从理论到实践的全面指南

本文全面介绍了如何使用TPM(可信平台模块)进行密钥管理,涵盖密钥的创建、存储、加载、迁移以及特殊密钥类型的使用。通过详细的操作步骤和代码示例,帮助读者掌握TPM密钥管理技术,确保系统的安全性和可靠性。

weixin_36212459的博客 242

Substrings

Problem Description You are given a number of case-sensitive strings of alphabetic characters, find the largest string X, such that either X, or its inverse can be found as a substring of any ...

几许情愁的博客 947

手把手教你学Simulink——基于自动驾驶辅助系统的场景实例:车道保持辅助系统(LKA)的仿真与实现

本文通过Simulink实例讲解车道保持辅助系统(LKA)的实现方法。首先介绍LKA从预警到主动控制的技术演进,阐述其系统架构、核心组件和工作原理。重点演示基于自行车模型的车辆横向动力学建模过程,以及使用线性二次调节器(LQR)设计横向控制器的详细步骤。教程包含四个仿真场景测试,分析关键指标如控制精度、舒适性和响应性。最后探讨LKA技术的发展方向,强调人机协同的安全理念。该实例为自动驾驶辅助系统开发提供了完整的Simulink实践方案。

MHD0815的博客 182

杭电1238 Substrings

<br />源码(C++):<br />#include <iostream><br /> #include <string><br /> using namespace std;<br /> int main()<br /> {<br />     int n,m,s,j,k,index,len,curlen,t;<br />     cin>>n;<br />     string str,substr,substrr;<br />     while(n)<br />     {<b

rightbag的专栏 1200

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

HDU 1238 Substrings

Problem : 1238 ( Substrings )     Judge Status : AcceptedRunId : 3950754    Language : G++    Author : nastaCode Render Status : Rendered By HDOJ G++ Code Render Version 0.01 Beta    简单的搜索题,杭电PPT的算法:“先将字符串按长度从短到长排序,枚举最短的字符串的子串,判断是否都是别的字符串的子串,求出最大长度即可。”写完提交

知易行难 710

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

杭电ACM1238——Substrings

题目的意思是,找到各个串的最长子串,输出长度。 我们找到最短的串,枚举这个串的所有子串,需要注意的是,这些子串的逆序也是可以的。 知道了这些,就可以写出代码了。 下面是AC的代码: #include #include using namespace std; char str[105][105]; int main() { char s1[105], s2[105]; int

XD 1110

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

hdoj 1238 Substrings

题目大意:求一组字符串的最长子串,子串包括逆串匹配 解题思路:选一个最短字符串,枚举其子串,跟其他字符串用kmp正匹配和逆匹配 注意没有子串匹配的情况。 #include #include #include #include using namespace std; const int maxn = 102; char str[maxn][maxn]; int slen[maxn

涛涛不解 804

HDOJ 1238 Substrings

Substrings Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 8078    Accepted Submission(s): 3688 Problem Description You are given a n

Chunzhen的博客 1002

杭电ACM1238(搜索题)

#include #include #include #include using namespace std; #define MAXN 100 vector strs; int n; bool find(string sub) { for(int i = 0; i < n; i ++) { if(string::npos == strs[ i ].find(sub))

adolphxy的专栏 606

杭电1238————简单枚举

Substrings Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7186    Accepted Submission(s): 3242 Problem Description You are given a

SixDay 495

SPOJ:Substrings(后缀自动机)

You are given a string S which consists of 250000 lowercase latin letters at most. We define F(x) as the maximal number of times that some string with length x appears in S. For example for string 'ab...

junior19的博客 494
上一篇: 杭电-1159Common Subsequence(LCS)
下一篇: 杭电-1513Palindrome(LCS+滚动数组)
Eric_keke
博客等级 码龄12年 37粉丝 221原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值