POJ 3415 Common Substrings 【长度不小于 K 的公共子串的个数】

Unity 之如何使用Pico4u锚点功能实现一个世界锁GameRoot 摘要 空间锚点技术是混合现实(MR)应用的核心,能永久记录虚拟物体的空间位置。文章介绍了在Unity中使用Pico SDK实现空间锚点的完整流程:1)环境配置需安装XR模块和Pico SDK;2)关键操作包括启动空间感知、创建/删除/查询/更新锚点;3)提供了经典应用案例,通过GameRoot节点实现场景固定和锚点同步。源码展示了基于XR交互工具包的锚点抓取与位置更新实现,为MR开发提供了实用参考方案。 阅读详情

传送门:http://poj.org/problem?id=3415

 

题意:给定两个串,求长度不小于 k 的公共子串的个数

解题思路:

常用技巧,通过在中间添加特殊标记符连接两个串,把两个串的问题转换为 一个串的问题
按照 height 分组。
这里有两种情况
一、后缀排名中, B的后缀在后 A的后缀在前,那么 height 就是 B的后缀 与前面 A的后缀的最长相同长度
二、后缀排名中,A的后缀在前 B的后缀在后,那么 height 就是 A 的后缀与 前面 B 的后缀的最长相同长度
所以要扫两遍,分别处理这两种情况
针对第一种情况而言:
用一个单调栈维护 最小公共长度,同时要记录每个最小公共长度的状态(即当前这种最小公共长度是包含了多少个 A 前缀的了)
每一次遇到一个 B 的后缀就统计与前面的A的后缀能产生多少个长度不小于 K 的公共子串。
对于第二种情况处理的方法也是一样。

 

AC code:

  1 /*
  2 POJ 3415
  3 给定两个字符串 A 和 B, 求长度不小于 K 的公共子串的个数,
  4 常用技巧,通过在中间添加特殊标记符连接两个串,把两个串的问题转换为 一个串的问题
  5 按照 height 分组。
  6 这里有两种情况
  7 一、后缀排名中, B的后缀在后 A的后缀在前,那么 height 就是 B的后缀 与前面 A的后缀的最长相同长度
  8 二、后缀排名中,A的后缀在前 B的后缀在后,那么 height  就是 A 的后缀与 前面 B 的后缀的最长相同长度
  9 所以要扫两遍,分别处理这两种情况
 10 针对第一种情况而言:
 11 用一个单调栈维护 最小公共长度,同时要记录每个最小公共长度的状态(即当前这种最小公共长度是包含了多少个 A 前缀的了)
 12 每一次遇到一个 B 的后缀就统计与前面的A的后缀能产生多少个长度不小于 K 的公共子串。
 13 对于第二种情况处理的方法也是一样。
 14 
 15 */
 16 
 17 #include <iostream>
 18 #include <algorithm>
 19 #include <cmath>
 20 #include <cstring>
 21 #include <cstdio>
 22 #define INF 0x3f3f3f3f
 23 #define LL long long
 24 #define rep(i, j, k) for(int i = j; i < k; i++)
 25 #define inc(i, j, k) for(int i = 1; i <= k; i++)
 26 using namespace std;
 27 const int MAXN = 2e5+10;
 28 int sa[MAXN];
 29 int t1[MAXN], t2[MAXN], c[MAXN];
 30 int Rank[MAXN], height[MAXN];
 31 
 32 //void Da(int s[], int n, int m)
 33 //{
 34 //    int i, k, p, *x = t1, *y = t2;
 35 //    rep(s, 0, m) c[s] = 0;
 36 //    rep(t, 0, n) c[x[t] = s[t]]++;
 37 //    rep(s, 1, m) c[s]+=c[s-1];
 38 //    for(i = n-1; i >= 0; i--) sa[--c[x[i]]] = i;
 39 //    for(k = 1; k <= n; k <<=1){                         //倍增
 40 //        p = 0;
 41 //        for(i = n-k; i < n; i++) y[p++] = i;
 42 //        for(i = 0; i < n; i++) if(sa[i] >= k) y[p++] = sa[i]-k;
 43 //        for(i = 0; i < m; i++) c[i] = 0;
 44 //        for(i = 0; i< n; i++) c[x[y[i]]]++;
 45 //        for(i = 1; i < m; i++) c[i]+=c[i-1];
 46 //        for(i = n-1; i >= 0; i--) sa[--c[x[y[i]]]] = y[i];
 47 //        swap(x, y);
 48 //        p = 1; x[sa[0]] = 0;
 49 //        for(i = 1; i < n; i++)
 50 //            x[sa[i]] = y[sa[i-1]]==y[sa[i]]&&y[sa[i-1]+k]==y[sa[i+k]]?p-1:p++;
 51 //        if(p >= n) break;
 52 //        m = p;
 53 //    }
 54 //}
 55 //
 56 //void getHeight(int s[], int n)
 57 //{
 58 //    int i, j, k = 0;
 59 //    for(i = 0; i <= n; i++) Rank[sa[i]] = i;
 60 //    for(i = 0; i < n; i++){
 61 //        if(k) k--;
 62 //        j = sa[Rank[i]-1];
 63 //        while(s[i+k] == s[j+k])k++;
 64 //        height[Rank[i]] = k;
 65 //    }
 66 //}
 67 
 68 void Da(int s[],int n,int m)
 69 {
 70     int i,k,p,*x=t1,*y=t2;
 71     for(i=0;i<m;i++)c[i]=0;
 72     for(i=0;i<n;i++)c[x[i]=s[i]]++;
 73     for(i=1;i<m;i++)c[i]+=c[i-1];
 74     for(i=n-1;i>=0;i--)sa[--c[x[i]]]=i;
 75     for(k=1;k<=n;k<<=1)
 76     {
 77         p=0;
 78         for(i=n-k;i<n;i++)y[p++]=i;
 79         for(i=0;i<n;i++)if(sa[i]>=k)y[p++]=sa[i]-k;
 80         for(i=0;i<m;i++)c[i]=0;
 81         for(i=0;i<n;i++)c[x[y[i]]]++;
 82         for(i=1;i<m;i++)c[i]+=c[i-1];
 83         for(i=n-1;i>=0;i--)sa[--c[x[y[i]]]]=y[i];
 84         swap(x,y);
 85         p=1;x[sa[0]]=0;
 86         for(i=1;i<n;i++)
 87             x[sa[i]]=y[sa[i-1]]==y[sa[i]]&&y[sa[i-1]+k]==y[sa[i]+k]?p-1:p++;
 88         if(p>=n)break;
 89         m=p;
 90     }
 91 }
 92 
 93 void getHeight(int s[],int n)
 94 {
 95     int i,j,k=0;
 96     for(i=0;i<=n;i++)Rank[sa[i]]=i;
 97     for(i=0;i<n;i++)
 98     {
 99         if(k)k--;
100         j=sa[Rank[i]-1];
101         while(s[i+k]==s[j+k])k++;
102         height[Rank[i]]=k;
103     }
104 }
105 
106 char str1[MAXN], str2[MAXN];
107 int r[MAXN];
108 int sta[MAXN], stb[MAXN];
109 
110 int main()
111 {
112     int k;
113     int n;
114     int len1, len2;
115     while(~scanf("%d", &k) && k){
116         scanf("%s %s", &str1, &str2);
117         len1 = strlen(str1);
118         len2 = strlen(str2);
119 //        cout << str1 << endl << str2 << endl;
120         n = len1+len2+1;
121         for(int i = 0; i < len1; i++) r[i]=str1[i];
122         r[len1] = 1;
123         for(int i = 0; i < len2; i++) r[i+len1+1]=str2[i];
124         r[len1+len2+1] = 0;
125         Da(r, n+1, 128);
126         getHeight(r, n);
127 //        for(int i = 0; i <= n; i++) cout << r[i] << " " ;
128 //        puts("");
129         LL ans = 0, ss = 0;
130         int top = 0;
131         for(int i = 2; i <= n; i++){
132             if(height[i] < k){
133                 top = 0;
134                 ss = 0;
135                 continue;
136             }
137             int cnt = 0;
138             if(sa[i-1] < len1){
139                 cnt++;
140                 ss+=height[i]-k+1;
141             }
142             while(top > 0 && height[i] <= sta[top-1]){
143                 top--;
144                 ss-=stb[top]*(sta[top]-height[i]);
145                 cnt+=stb[top];
146             }
147             sta[top] = height[i];
148             stb[top++] = cnt;
149             if(sa[i] > len1) ans+=ss;
150         }
151 //        cout << ans << endl;
152         ss = 0;top = 0;
153         for(int i = 2; i <= n; i++){
154             if(height[i] < k){
155                 top = 0;
156                 ss = 0;
157                 continue;
158             }
159             int cnt = 0;
160             if(sa[i-1] > len1){
161                 cnt++;
162                 ss+=height[i]-k+1;
163             }
164             while(top > 0 && height[i] <= sta[top-1]){
165                 top--;
166                 ss-=stb[top]*(sta[top]-height[i]);
167                 cnt+=stb[top];
168             }
169             sta[top] = height[i];
170             stb[top++] = cnt;
171 //            cout << ss << endl;
172             if(sa[i] < len1) ans+=ss;
173         }
174         printf("%lld\n", ans);
175     }
176     return 0;
177 }
View Code

 

SAP-MM-采购过账接口(与WMS集成)-代码 1、判断传入值非空检验; 2、判断过账日期是否允许在当前期间; 3、判断是否为集采订单业务,是否审批完成; 4、判断是否发布标准成本发布(此业务场景与价格控制3+S有关) 5、保存日志表; 6、判断业务公司订单审批状态; 7、创建STO交货单、集采公司订单过账、STO公司间创建交货单、交货单过账(两步法)、过账失败回滚(冲销交货、删除交货单、冲销集采入库) 阅读详情

相关推荐

UE4游戏开发:GameInstance与GameMode的实战应用与避坑指南

本文深入解析了UE4中GameInstance与GameMode的核心差异与实战应用。GameInstance作为贯穿游戏进程的全局单例,负责跨关卡数据持久化与系统管理;而GameMode则定义特定关卡内的游戏规则与逻辑,随关卡加载销毁。文章通过数据存储、动态模式切换及网络游戏等场景,提供了清晰的应用指南与常见避坑方案,帮助开发者构建更健壮的UE4游戏架构。

kubernetes8ctl的博客 233

POJ3415:Common Substrings——题解

http://poj.org/problem?id=3415 给定两个字符串A 和B,求长度不小于k 的公共子串的个数(可以相同)。 论文题,和上道题(POJ2774)类似,首先想到现将AB串合并,然后子串可以表示成字符串后缀的前缀,于是我们比较任意两个A后缀和B后缀,用height求出他们的公共子串长度就很好做了。 (不懂为什么好做的可以看SPOJ694) 那么最坏的想法就是每遇...

weixin_34161064的博客 144

STM32 bootloader程序跳转到APP卡死在B_ENDP_ALIGN,原因:有未处理的中断。解决方法:重启系统

Bootloader和App中都用到了串口,定时器等,所以从Bootloader跳转App后未卡死。 后来写的另一个App里没有用到这几个外设,然后就是无限的卡死。 现在Bootloader中跳转App之前将已打开的外设关掉,再跳转至App就不再出现卡死。  if(((*(vu32*)(APPLICATION_ADDRESS+4))&0xFF000000)==0x08000000) {

jingzhixingyun的博客 7922

poj3415_Common Substrings

题意 给定两个字符串,求长度大于等于k的公共子串数。 分析 将两个字符串中间加个特殊字符拼接,跑后缀数组。 将题目转化为对每一个后缀求\(\sum_{j=1}^{i-1}lcp(i,j)\),且后缀\(i\)和\(j\)属于不同字符串。 由于\(lcp\)只跟\(h\)数组的区间最小值有关,因此对于单调递减的\(h[i]\)我们可以合并贡献和个数,维护一个单调栈。 分别统计\(a\)串...

awrd28452的博客 141

[图解]SysML与EA实战:住宅安全系统接口块设计全解析

本文详细解析了使用SysML和EA工具进行住宅安全系统接口块设计的全流程。从系统上下文图入门到接口块实战技巧,涵盖块定义图与内部块图的视角转换,以及多图协同建模方法论。特别分享EA工具的高效操作指南和常见问题避坑建议,帮助工程师掌握精确信号定义、端口方向设置等关键技能,提升安防系统设计效率。

weixin_29234509的博客 340

数字后端实战指南 | Innovus Function ECO全流程解析(从LAB到Tapeout)

本文深入解析了在Cadence Innovus工具中进行Function ECO的全流程实战指南。从LAB环境搭建到Tapeout前的签核验证,详细拆解了Pre-mask与Post-mask ECO的核心步骤、关键命令(如ecoDesign)以及常见避坑方案。重点阐述了如何应对时序、DRC等挑战,并强调了备用单元管理与严格验证的重要性,是数字后端工程师提升综合能力的必备参考。

weixin_28452161的博客 647

POJ-3415 Common Substrings 后缀数组

  题目链接:http://poj.org/problem?id=3415   求两个串的长度不小于K的公共字串的个数。   利用height[]来维护一个单调递增的栈,即栈保存的是满足要求的heigiht数组的最小值,附加维护栈中相邻两个元素之间的个数。 1 //STATUS:C++_AC_813MS_6532KB 2 #include<stdio.h> 3...

weixin_30262255的博客 146

【KDD2024】ShapeFormer:用于多元时间序列分类的Shapelet Transformer

多元时间序列分类(MTSC)因其在现实世界中的广泛应用而吸引了大量研究关注。最近,Transformer在MTSC中取得了先进的性能。然而,

m0_52597077的博客 4761

poj 3415 Common Substrings

题目链接:http://poj.org/problem?id=3415 题目分类:后缀数组 题意:给出两个串和一个数字k,求两个串的公共字串大于等于k的数目 代码: //#include<bits/stdc++.h> #include<stdio.h> #include<math.h> #include<algorithm> #i...

weixin_30530339的博客 95

Python学习(一)

快速入门 1.Linux系统中是可以直接使用Python进行编程,具体如下: 进入Python:在linux的Terminal中输入 Python ,进入Python的命令行; 退出Python:在linux的Terminal中输入quit() 或 exit() 或 ctrl +d ,再回车,退出Python的命令行。 2.python的源程序就是一个特殊格式的文本文件,可以使用任意文本编辑软件做Python的开发。 3.Python程序的文件扩展名通常都是 .py。 4.执行Python程序的方式:在

SummerXRT的博客 1283

第6篇:ESP32连接无源喇叭播放音乐《涛声依旧》

相邻两个音之间的倍数是2^(1/12),约等于1.0594630943592952645618252949463)。这样一来,高八度的do频率是低八度do的两倍。我们把频率440赫兹作为中央C ,C调的歌就是把频率440赫兹当作do,乐谱中写作:1=C。一个八度分成12份,八个八度的十二平均音率对应的频率如下(从33Hz到7902Hz)。相邻的两个音之间的差一个半音,12345671之间的间隔分别是“全全半全全全半”。D调的歌就是把从440后面第二个音494赫兹当作do,乐谱中写作1=D。

Txwtech 1428

poj 3415 Common Substrings

这题差错查死我了。。。最后竟然是中间过程爆int了,好囧。。 思路:把a串和b串接起来,中间加个‘$’,求后缀。             线性的遍历h[i]数组,然后每段公共前缀大于K的区间里的a串和b串的数量相乘即可。 #include #include #include #include #define LL __int64 using std::min; using std::reve

u010690055的专栏 1257

ros_gz_bridge__镜像__readme

Run。

1117

POJ3415 Common Substrings【后缀数组(长度不小于 k 的公共子串的个数)】

题目描述: RT,给定两个字符串 A 和 B,求长度不小于 k 的公共子串的个数(可以相同)。 样例 : A=“xx”,B=“xx”,k=1,长度不小于 k 的公共子串的个数是 5。 题目分析: 基本思路是计算 A 的所有后缀和 B 的所有后缀之间的最长公共前缀的长度,把最长公共前缀长度不小于 k 的部分全部加起来。先将两个字符串连起来,中间用一个没有出现过的字符隔开。按 height 值分组后,...

Master.Yi的博客 234

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

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

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

Common Substrings POJ - 3415(长度不小于k的公共子串的个数)

题意:   给定两个字符串A 和 B, 求长度不小于 k 的公共子串的个数(可以相同) 分两部分求和sa[i-1] > len1 sa[i] < len1 和 sa[i-1] < len1 sa[i] > len1 #include <iostream> #include <cstdio> ...

babing2770的博客 165

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

POJ - 3415 Common Substrings(长度不小于K的公共子串个数)

#include<cstdio> #include<cstring> #include<iostream> using namespace std; typedef long long ll; // sa[i]: 排名是i位的是第几个后缀 // rk[i]: 第i个后缀的排名是多少 // height[i]: sa[i]与sa[i-1] const int N=200010; char s[N],s1[N],s2[N]; int rk[N],sa[N],cnt[N],he

Fighting_Peter的博客 294

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

POJ 3415 Common Substrings (后缀数组,长度不小于k的公共子串的个数)

Common Substrings Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 5495   Accepted: 1822 Description A substring of a string T is defined as:   T(i, k)=TiTi...

weixin_34416754的博客 133

POJ - 3415 Common Substrings(后缀数组求长度不小于 k 的公共子串的个数+单调栈优化)

Description A substring of a string T is defined as: T( i, k)= TiTi+1... Ti+k-1, 1≤ i≤ i+k-1≤| T|. Given two strings A, B and one integer K, we define S, a set of triples (i, j, k): S =

那些年 1498

POJ 3415 Common Substrings(长度不小于k 的公共子串的个数--后缀数组+单调栈优化)

题意:给定两个字符串A 和B,求长度不小于k 的公共子串的个数(可以相同)。 样例1: A=“xx”,B=“xx”,k=1,长度不小于k 的公共子串的个数是5。 样例2: A =“aababaa”,B =“abaabaa”,k=2,长度不小于k 的公共子串的个数是22。 思路: 如果i后缀与j后缀的LCP长度为L, 在L不小于K的情况下, 它对答案的贡献为L - K + 1. 于是

kalilili的专栏 835

POJ - 3415 Common Substrings(后缀数组求长度不小于 k 的公共子串的个数+单调栈优化)...

Description A substring of a stringTis defined as: T(i,k)=TiTi+1...Ti+k-1, 1≤i≤i+k-1≤|T|. Given two stringsA,Band one integerK, we defineS, a set of triples (i,...

weixin_30838921的博客 124

POJ 3415 Common Substrings(长度不小于K的公共子串的个数+后缀数组+height数组分组思想+单调栈)...

http://poj.org/problem?id=3415 题意:求长度不小于K的公共子串的个数。 思路:好题!!!拉丁字母让我Wa了好久!!单调栈又让我理解了好久!!太弱啊!! 最简单的就是暴力枚举,算出LCP,那么这个LCP对答案的贡献就是$x-k+1$。 我们可以将height进行分组,大于等于k的在同一组,如果两个后缀的最长公共子串>=k,那么它们肯定在同一个组内。现...

weixin_30707875的博客 141

poj 3415 Common Substrings(长度大于k的相同子串对数xian 后缀数组+单调桟统计)

地址:http://poj.org/problem?id=3415 题意:给你两个字符串,还有一个数字K,要求这两个字符串长度大于等于K的相同子串对数,具体看题目 分析:这题求相同子串,自然就会让人想到后缀数组之类的解法,不过后缀数组只能求出最长的公共子串,还有一些公共前缀的信息,没办法完成统计子串对数,我想了半天都没想出办法,然后看了一眼讨论,有人说是单调性。。。我就继续往这方面思考了,仔细

志当存高远 3082

POJ 3415 Common Substrings(后缀数组+单调栈)

转载请注明出处,谢谢http://blog.csdn.net/acm_cxlove/article/details/7854526       by---cxlove  题目:求出长度不小于k的公共子串个数 http://poj.org/problem?id=3415  继续论文上的题目。 计算A的某个后缀与B的某个后缀的最长公共前缀长度,如果长度L大于k,则加上L-k+1组。

窝不是爱酱,喵~~~~ 7467

poj 3415 Common Substrings 后缀数组

题目链接:点我 题意:求出长度不小于k的公共子串个数 思路:本来想套个二分查询的,但是发现真的难搞,转移也不知道错哪了,用单调栈写,发现转移也不好写,于是基本都是借鉴的… 下面是代码 #include <set> #include <map> #include <stack> #include <queue> #include <vector&...

qq_40728222的博客 266

POJ 3415 Common Substrings

题意很简单,找两个串长度大于等于k的公共子串数; 需要用单调队列来优化,用两次分别统计  A串与在A前面的B串的公共子串数 和  B串与在B前面的A串的公共子串数 过程大概是每入栈一个元素结果都加上一个tot,然后就是维护这个tot。。。 如果入栈的元素比栈顶的大,那tot就加上h [ i ] - k + 1,否则,就要维护栈单调递增的性质,把前面比它height值大的元素去

码代码的猿猿 1308
上一篇: POJ Football Game 【NIMK博弈 && Bash 博弈】
下一篇: HDU 6034 【贪心】
莜莫oO
博客等级 码龄9年 7粉丝 226原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址