POJ_n-gram串频统计

n-gram串频统计(统计字符串字串出现次数最多的)(计蒜客) 字符子串数目统计 阅读详情
总时间限制:
1000ms
内存限制:
65536kB
描述

在文本分析中常用到n-gram串频统计方法,即,统计相邻的n个单元(如单词、汉字、或者字符)在整个文本中出现的频率。假设有一个字符串,请以字符为单位,按n-gram方法统计每个长度为 n 的子串出现的频度,并输出最高频度以及频度最高的子串。所给的字符串只包含大小写字母,长度不多于500个字符,且 1 < n < 5。

如果有多个子串频度最高,则根据其在序列中第一次出现的次序依次输出,每行输出一个,如果最高频度不大于1,则输出NO。

输入
第一行为n;
第二行为字符串。
输出
输出最高频度以及频度最高的所有子串。若最高频度不大于1,只输出一行NO。
样例输入
3
abcdefabcd
样例输出
2
abc
bcd
提示
样例中,所有的3-gram是:abc,bcd,cde,def,efa,fab,abc,bcd。最后面的cd不足以形成3-gram,则不考虑。这样,abc 和 bcd 都出现了2次,其余的只出现了1次。
来源
元培-From Whf

思路:在比较的过程中不断把未出现的子串加入数组,出现的子串频次加一

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<string.h>
#include<queue>
using namespace std;
int str[30];
char buf[30][80];
int main() {
   
   
	int n;
	scanf("%d", &n);
	string s;
	s.resize(505
【n-gram算法】一篇文章讲透~ n-gram算法作为一种基于统计的NLP算法,在文本分析和处理中发挥着重要作用。通过统计文本中连续n个词的序列的频率信息,n-gram为文本生成、语言模型构建、文本分类等任务提供了有力的支持。然而,n-gram算法也存在一些局限性,如数据稀疏性、上下文信息有限以及计算复杂度高等问题。因此,在实际应用中,我们需要根据具体任务和数据特点选择合适的n值和算法参数,以充分发挥n-gram算法的优势并克服其局限性。 阅读详情

相关推荐

NLP实践-SwiftKey预测输入法(一)

目录 0.准备阶段: ·了解数据的结构: ·数据的来源: ·依靠外部的数据材料来优化此数据的处理 ·NLP的普遍处理步骤 ·text mining的普遍步骤和要求 ·NLP与data science 基础知识的联系:  1.加载与初步处理数据: ·加载数据。 ·了解基本数据的内容  -标记化       -亵渎过滤 ·基本处理数据   ·相关练习: 2、探索数据阶段...

Kidpea LAU ' BLOG 1872

手把手构建可解释问答引擎:从Transformer原理到医疗QA落地

问答系统(Question Answering)是自然语言处理的核心任务之一,其本质是让模型理解问题、定位上下文、精准抽取答案跨度并评估可靠性。基于Transformer架构的模型凭借自注意力机制与长程建模能力,成为现代问答系统的主流基座,但直接调用Hugging Face pipeline往往导致答案不可靠、类型混淆与跨段落失效。本文聚焦抽取式问答(Extractive QA)的技术内核,深入解析问题类型识别、动态上下文检索、边界一致性建模与置信度校准四大关键环节,结合医疗等垂直领域真实案例,揭示如何将黑

weixin_30435261的博客 336

440MB离线翻译模型技术解析:端侧AI的工程化实践

离线翻译模型是面向终端设备部署的轻量化机器翻译系统,其核心在于通过模型蒸馏、INT4混合精度量化、结构化稀疏与任务专用架构等技术,在严苛资源约束下实现低延迟、高准确率的本地化推理。相比云端大模型,它不追求通用能力,而聚焦高频场景(如中英/中日短句、App界面文案、口语化表达)的确定性输出,显著降低网络依赖、功耗与响应时延。该技术已广泛应用于微信翻译、海外版App本地化及IoT设备多语言支持等场景,成为端云协同AI架构的关键一环。本文深入剖析440MB体积下的模型设计逻辑、量化部署细节与实操避坑指南。

aigui1439的博客 405

NOI 1.13.26 n-gram串频统计 题解

n-gram串频统计 题解 题目 26:n-gram串频统计 总时间限制: 1000ms 内存限制: 65536kB 描述 在文本分析中常用到n-gram串频统计方法,即,统计相邻的n个单元(如单词、汉字、或者字符)在整个文本中出现的频率。假设有一个字符串,请以字符为单位,按n-gram方法统计每个长度为 n 的子串出现的频度,并输出最高频度以及频度最高的子串。所给的字符串只包含大小写字母,长度不...

jerry20183的博客 740

n-gram串频统计(再看)

描述 在文本分析中常用到n-gram串频统计方法,即,统计相邻的n个单元(如单词、汉字、或者字符)在整个文本中出现的频率。假设有一个字符串,请以字符为单位,按n-gram方法统计每个长度为 n 的子串出现的频度,并输出最高频度以及频度最高的子串。所给的字符串只包含大小写字母,长度不多于500个字符,且 1 < n < 5。 如果有多个子串频度最高,则根据其在序列中第一次出现的次序依次输出,每行输出一个,如果最高频度不大于1,则输出NO。 输入 第一行为n; 第二行为字符串。 输出 输出最高频度以

xuyang0905的博客 656

从零完成 STM32 + ESP-01S + 云服务器 TCP 通信测试

STM32 通过 USART3 控制 ESP-01S 接入手机 2.4 GHz 热点,随后连接公网云服务器 8.152.204.86:9002。云端在同一 TCP 连接中连续收到 seq=1~6 的测试报文,5 个发送间隔平均约 5.4 秒,说明本次 TCP 上行链路已经打通。

weixin_51387720的博客 308

AD/Protel老手才知道的PCB过孔查看技巧:3分钟分清通孔、盲孔和埋孔

本文为PCB设计工程师提供了在Altium Designer/Protel中快速鉴别通孔、盲孔和埋孔的实用技巧。通过层叠管理器、高级筛选工具和实战五步法,帮助用户在3分钟内精准识别过孔类型,提升设计效率和电路性能。特别适合处理高密度HDI板卡中的复杂过孔布局。

weixin_29164497的博客 572

RT-Thread Studio使用笔记(四):带片外Flash(W25Q128)的OTA(YModem)

前言 在学习OTA之前,请先参考上两篇博客写的关于SPI设备及W25Q128的使用方法,传送门: https://blog.youkuaiyun.com/tigerots/article/details/107423633 https://blog.youkuaiyun.com/tigerots/article/details/107933991 如何使用OTA 一. 制作BootLoader 打开Bootloader 在线获取地址,注册,并根据RT-thread官方文档生成BootLoader,官方文档已经写的很清楚,再此

tigerots的专栏 4008

无监督低照度增强实战:用ZeroDCE和SCI拯救你的夜间照片(附PyTorch代码)

本文深入探讨了无监督低照度图像增强技术,重点解析了ZeroDCE和SCI两大代表性模型的核心原理与实战应用。通过对比分析两者的技术路径、网络结构及性能特点,并附上详细的PyTorch代码实现,旨在帮助读者掌握无需配对数据即可有效提升夜间照片画质的深度学习解决方案。

git9versioner的博客 489

游戏开发实战:用UE4 Marschner模型打造次世代头发渲染(附Shader代码解析)

本文详细解析了如何在UE4中使用Marschner模型实现次世代头发渲染,包括Shader代码逐行解读与参数调优。通过对比传统Kajiya-Kay模型,展示了Marschner模型在物理精确性和视觉效果上的优势,并提供了性能优化与实战技巧,帮助技术美术师提升游戏角色渲染品质。

weixin_28223453的博客 240

汽车行业OTD业务模式入门学习

本文是在学习彭俊松老师的《汽车行业整车订单交付系统》后,对于OTD理解的一些摘录,供诸位参考学习。

qq_40664711的博客 1万+

【HAL库】STM32CubeMX开发----STM32F407----ETH+LWIP----TCPclient客户端

STM32F407开发板 为TCPclient客户端,PC端 为TCPserver服务端,相互之间的发送和接收实验。

MQ0522的博客 3047

YOLOv11涨点改进| Kimi团队 2026 |独家创新首发、注意力改进篇|爆火AttnRes残差自注意力模块,含多种创新改进,借助残差思想,缓解细节信息在传播过程中被稀释,促进YOLOv11涨点

🔥本文提出AttnRes残差自注意力模块,通过深度维度的注意力加权机制替代传统固定残差累加方式,使YOLOv11网络能自适应选择更有价值的历史层特征进行聚合。该方法缓解了浅层细节信息在深层传播过程中被稀释的问题,有效融合浅层纹理与深层语义特征,提升小目标、密集目标和复杂场景的检测能力。AttnRes还改善了深层网络的梯度分布与训练稳定性,增强模型收敛质量和泛化能力。实验表明,该模块能以较小计算开销显著提升YOLOv11的特征表达能力、检测精度和整体鲁棒性。文中详细介绍了模块结构、实现原理、优势特点

Ai缝合怪、助力小伙伴高效发论文 124

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

ssm框架搭建

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

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

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

上一篇: POJ 垂直直方图
下一篇: C++杂记
softwareX4
博客等级 码龄9年 21粉丝 63原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值