HackerRank: Sam and sub-strings

HackerRank-Problem-Solution:hackerrank问题的所有解决方案 立即下载

题目链接

分析

考虑每一位数字对最终总和的贡献,画出表格分析小例子得到模式。

解法一: 模式

s = raw_input()
n = len(s)
candies = 0
mul = 1
MOD = 1000000007
for index in xrange(n - 1, -1, -1):
    candies = (candies + (ord(s[index]) - ord('0')) * mul *(index + 1)) % MOD
    mul = (mul * 10 + 1) % MOD
print candies

解法二: 动态规划

s = raw_input()

n = len(s)
MOD = 1000000007
pre = int(s[0])
candies = pre
for i in xrange(1, n):
    pre = (ord(s[i]) - ord('0')) * (i + 1) + pre * 10
    pre = pre % MOD
    candies = (candies + pre) % MOD
print candies % MOD
WIFI基础入门--802.11g--增强速率物理层ERP--15 WIFI基础入门--802.11--增强速率物理层--191.802.11g的组件保护机制 1.802.11g的组件 802.11g其实是将好几种物理层规范合而为一。虽然统称为增强速率物理层(Extended Rate PHY简称ERP),但是实际上ERP有好几种不同的方式: ERP-DSSS与ERP-CCK 这两种模式向下兼容于原始直接序列规范(1Mbps与2Mbps),以及所提到的802.11... 阅读详情

相关推荐

Stata实战:用双向固定效应模型分析房价,从数据清洗到结果解读(附完整代码)

本文详细介绍了如何使用Stata实现房价数据的双向固定效应模型分析,从数据清洗到结果解读的全流程。通过具体代码示例,帮助读者掌握面板模型的应用技巧,特别适合经济学和金融学研究者进行房价影响因素分析。

weixin_31528001的博客 277

*[hackerrank]Sam and sub-strings

https://www.hackerrank.com/contests/w3/challenges/sam-and-substrings DP。注意到以N[i]结尾的每个字符串的子数字和有规律: 53125 | 3 53 | 1 31 531 | 2 12 312 5312 sd[2] = 1 + 31 + 531 = 563sd[3] = 2 + 12 + 312 + 53...

weixin_30367873的博客 183

打开LWIP_DEBUG的打印信息调试

在lwip 2.1.2的版本,打开的debug 调试的步骤: 1.在debug.h 文件中找到debug打印的定义 默认LWIP_DEBUG这个宏没有定义, 2.在lwipopt.h 文件中或者其他文件定义 一下LWIP_DEBUG这个宏, 3.在opt.h 中可以打开各种宏的调试信息, /* --------------------------------------- ---------- Debugging options ---------- ---------...

haidscs的博客 9880

Sam and substrings

https://www.hackerrank.com/challenges/sam-and-substrings/problem fSamantha 和 Sam 正在玩一个游戏。他们面前有 ‘N’ 个球,每一个从 0 到 9 编号,但是第一个球不会为 0. Samantha 计算了这些球构成的字符串的所有子串。对每一个子串,如果子串为S,Sam 必须向一个初始为空的盒子里边放 S 块糖。Sam ...

Do not mess it up 331

线上专利申请(超详细)| 签名确认

在【法人登录】页面点击【证书登录】按钮,弹出证书登录提示框,点击【确 认】按钮,进入到输入证书密码页面,点击【取消】按钮,取消本次操作。企业在提交申请时,需要增加签名,如使用企业账户点击提交,会弹出“法人、代理机构不能签名,请使用经办人签名”,这个时候就需要换个账号了。在需要签名时,将专利官网的登录方式点击法人登录,选择扫码登录,使用移动端经办人账户的扫一扫功能扫描登录。登录完成后,再点击签名,使用移动端扫一扫功能,扫描签名,输入证书号,确认签名,并提交。最后,祝大家的申请都成功!

weixin_62112323的博客 9112

【实用运维脚本】Windows 批量 TCP 端口检测(tcping 一键巡检)

摘要:本文介绍一款高效的Windows批量TCP端口检测脚本,适配tcpingv0.39工具,实现多服务器一键巡检。脚本具有进度可视化、双日志输出、自动容错等优势,支持注释行过滤和UTF-8编码。 使用仅需三步: 1)下载tcping工具 2)编辑目标列表 3)运行脚本即可自动检测并生成带编号的检测报告。 该方案解决了手动检测效率低、易遗漏的问题,特别适合日常运维中的端口连通性检查,实测稳定可靠,开箱即用。

蕲士|D365 & 服务器运维,心有东坡,行稳致远。 802

SPOJ 8222 Substrings(SAM)

转载请注明出处,谢谢http://blog.youkuaiyun.com/ACM_cxlove?viewmode=contents    by---cxlove 题意:给一个字符串S,令F(x)表示S的所有长度为x的子串中,出现次数的最大值。求F(1)..F(Length(S)) (感谢clj的翻译>_ http://www.spoj.pl/problems/NSUBSTR/ 建立 SA

SCUT_Pein 929

【施磊】C++课程笔记目录

【C++编程】施磊老师C++笔记目录

GeniusAng的博客 4124

spoj8222 NSUBSTR - Substrings(SAM+dp)

我们首先建出后缀自动机,每个节点的|Right|就是这个节点代表的串的出现次数。可以基数排序做出拓扑序之后倒着更新sz。考虑dp[i]表示长度为i的串最多的出现次数,显然有dp[i]不升。于是我们每次更新一个节点时,其实只要更新dp[mx[i]]即可,最后再倒着更新一遍dp[i]=max(dp[i],dp[i+1])即可。

Icefox的博客 309

SAP Joule for Consultants 与 Joule for Developers 全面解读

SAP推出面向不同用户群体的Joule AI助手:开发者版(Joule for Developers)专注于编码提效,嵌入开发工具链辅助生成、重构和测试代码;顾问版(Joule for Consultants)聚焦业务场景,集成SAP云应用知识库,为咨询项目提供方案设计、差距分析和实施指引。两者共享AI底座但功能侧重点不同:开发者版优化技术开发流程,顾问版加速项目交付周期。典型应用场景包括制造业云转型方案制定和ABAP代码迁移,分别展示了两版本在业务决策支持和技术实施中的价值。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 545

uniapp - 实现APP后台持续定位+手机息屏后能持续上传位置信息数据,详解后台保活持续运行+手机锁屏保证后台持续/实时定位的解决方案及示例源码(完美兼容安卓android与苹果ios系统手机)

使用uniapp开发app实现后台保活定位能力,uniapp实时定位保活 息屏定位后台运行,uniapp APP实时定位高德 后台运行 支持锁屏息屏运行,持续获取定位信息,uniapp App端后台间隔时间发送定位功能实现,UniApp实现手机应用常活,固定时间内上传手机位置信息,后台(或锁屏)持续/实时定位的实现方案,uni-app后台持续定位,锁屏后能持续上传位置信息,实现后台定位持续无限制定位高德定位,百度定位,UniApp后台持续定位保如何在APP退到后台时保持定位服务,uniapp 切换app仍能

🏆 前端领域优质创作者 1万+

14.3-6 MIN GAP

请说明如何维护一个支持操作MIN-GAP的动态数据集Q,使得该操作能够给出Q中两个数之间的最小差幅。例如,Q={1,5,9,15,18,22},则MIN-GAP(Q)返回18-15=3,因为15和18是其中最近的两个数。使用操作INSERT,DELETE,SEARCH和MIN-GAP尽可能高效,并分析它们的运行时间。 题目中的Q是一个有序序列,但输入序列P不一定是有序的。 由于以RED-BLACK

幸福在路上 1238

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

UVa 10829 - L-Gap Substrings (后缀数组)

UVA - 10829 L-Gap Substrings Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu [Submit]   [Go Back]   [Status]   Description Problem J L-Gap Substri

zhaosdfa 1053

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

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

bzoj 2534: Uva10829L-gap字符串 (后缀数组+ST表)

题目描述传送门题目大意:有一种形如uvu形式的字符串,其中u是非空字符串,且V的长度正好为L,那么称这个字符串为L-Gap字符串 。 给出一个字符串S,以及一个正整数L,问S中有多少个L-Gap子串.题解同bzoj 2119: 股市的预测代码#include<iostream> #include<cstring> #include<algorithm> #include<cstdio> #incl

clover_hxy的博客 627

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

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

UVA 10829 L-Gap Substrings(后缀数组+枚举区间优化)

题目大意:给定一个字符串,问有多少字符串满足UVU的形式,要求U非空,V的长度为g。 思路:首先,很容易想到用后缀数组求LCP,能够在O(1)的时间求任意2点的lcp。 一开始我想的是枚举v的起点,然后在v的左侧枚举左端u的起点,设左端u的起点为i,那么u_len等于v的起点减i,然后右端起点固定为j=i+u_len+v_len,那么只要lcp(i,j)为u_len,则ans++。  很可惜,

Eason的博客 2756

希尔排序

/*希尔排序又称缩小增量排序,它也是一种属插入排序的方法 但在时间效率上,较直接插入排序有加大的改进,它的基本思想是: 先将整个待排序记录序列分割成若干个子序列分别直接进行直接插入排序,待 整个序列中的记录”基本有序“时,再对全体记录进行一次直接插入排序 gap增量,即组数也是间隔值 */ #include<stdio.h> void Shell(int *arr,int len,...

Dthinking的博客 354

[BZOJ2534]Uva10829L-gap字符串(后缀数组+st表)

题目描述传送门题目大意:求字符串s中有多少子串,满足形如ABA形式,其中A是非空字符串,且B的长度正好为L题解这道题和股市的预测实际上时一样的…不过现在忘得快干净了… B的长度已知是L,首先枚举A的长度i 然后将整个字符串按照长度为i分块,枚举每一个块的端点,设为l,令r=l+i+m,然后对l和r求lcp和lcs,可以发现长度为i+L+i的子串在长度为lcp+lcs的范围内滑动都是合法的,所以对

zyf2000 1234

uva10829 - L-Gap Substrings

后缀数组、有点神的做法

ACoder 293

HackerRank之Java Strings Introduction

Question: Answer: Scanner sc=new Scanner(System.in); String A=sc.next(); String B=sc.next(); System.out.println(A.length()+B.length()); System.out.println(A.compareTo(B)&gt;0?"Yes":"No"); System....

一个人的博客 347

UVA 10829 - L-Gap Substrings(后缀数组)

UVA 10829 - L-Gap Substrings 题目链接 题意:一个字符串如果形如UGU,的形式,G的长度为L,那么称这个字符串为L串,给定一个字符串,问这个字符串子串为g串的个数 思路:做这题前先做了POJ3693,有一个思想就是枚举长度分段,这样的话对于一个U长度为l的而言,只要在当前位置和当前位置之后(l + g)的位置分别向前向后找lcp,两个lcp加起来的长度

Remilia's 2217

bzoj 2534: Uva10829L-gap字符串 后缀数组+线段树合并

不是很懂那些很短的代码是什么方法,感觉好大啊。。        首先跑一个后缀数组,然后按照height数组从大到小合并,那么合并的两部分的lcp就是height的值,那么用经典的启发式合并求出答案就好了。        本来想用set的,发现set不兹瓷查询第k大,又不想写平衡树,最后冷静了一下写了个线段树合并。         tm它居然是字符串,我一直以为是小写字母串,爆了好几发oj,

lych的博客 991

HackerRank - Python部分

给定一个字符序列,计算出随机选取k个元素中包含’a’的概率。本题属于简单题,主要思路就是利用公式1−C(N−m,k)/C(N,k)1 - C(N-m,k)/C(N,k)来得到概率。from collections import Counter from functools import reduce import operator def C(n,k): return reduce(oper

pyb的博客 2211

[bzoj2534]Uva10829L-gap字符串

题目描述有一种形如uvu形式的字符串,其中u是非空字符串,且V的长度正好为L,那么称这个字符串为L-Gap字符串 给出一个字符串S,以及一个正整数L,问S中有多少个L-Gap子串. L≤10 字符串长≤50000分析这道题难度挺大的。。。 考虑一个合法的UVU串。假设两个U结束位置分别是i,j(i < j)。 设两个前缀i,j的最长公共后缀长度为len。那么i,j合法时满足以下两个条件:

WorldWide_D的博客 588
上一篇: HackerRank: Bricks Game
下一篇: HackerRank: Play with words
junchen1992
博客等级 码龄10年 6粉丝 154原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值