lcs

Is there any algorithm to address the longest common subsequent problem with different weights for each character?

荒凉一梦 提交于 2019-12-10 10:29:26
问题 I'm looking for an algorithm that addresses the LCS problem for two strings with the following conditions: Each string consists of English characters and each character has a weight. For example: sequence 1 (S1): "ABBCD" with weights [1, 2, 4, 1, 3] sequence 2 (S2): "TBDC" with weights [7, 5, 1, 2] Suppose that MW(s, S) is defined as the maximum weight of the sub-sequence s in string S with respect to the associated weights. The heaviest common sub-sequence (HCS) is defined as: HCS = argmin

longest common substring between 2 HUGE files - out of memory: java heap space

…衆ロ難τιáo~ 提交于 2019-12-08 12:21:11
问题 I'm completely brain fried after this, I need to find the longest common substring between 2 files, a small one and a HUGE one. I don't even know where to start to begin the search, heres what I have so far import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class MyString { public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new FileReader("MobyDick.txt")); BufferedReader br2 = new BufferedReader(new

LCS ALGORITHM ( example )

荒凉一梦 提交于 2019-12-07 15:13:34
There's a dynamic programming algorithm to find the Longest Common Subsequence of two sequences. How can I find the LCS algorithm of two sequences X and Y. (Test of correctness) (a) X = ABEDFEESTYH Y=ABEDFEESTYHABCDF (b) X = BFAAAABBBBBJPRSTY Y=ABCDEFGHIJKLMNOPRS (c) X = ϕ (Empty Sequence), Y = BABADCAB Here is an online calculator http://igm.univ-mlv.fr/~lecroq/seqcomp/node4.html Java public class LCS { public static void main(String[] args) { String x = StdIn.readString(); String y = StdIn.readString(); int M = x.length(); int N = y.length(); // opt[i][j] = length of LCS of x[i..M] and y[j.

CSP2019模拟题一

两盒软妹~` 提交于 2019-12-03 15:05:08
contest1 A. 最大子段和 描述 从这个序列中选出不相交的两个连续段,要求它们的和最大。 输入 第一行一个正整数 n n,表示序列长度。 接下来一行 n 个整数 a 1, a 2 , a 3 ,..., an ,表示题目描述中的序列。 输出 一行一个整数表示最大值。 样例 输入 7 2 -4 3 -1 2 -4 3 输出 7 提示 n<=1e5,a[i]<=1e9 solution 这道题实际上就是最长公共子序列的变形,只要从左边跑一边LCS,再从右边跑一边LCS,然后两边相加就可以了 下面呈上代码 来源: https://www.cnblogs.com/yulinss/p/11801445.html

efficient longest common subsequence algorithm library?

主宰稳场 提交于 2019-12-03 09:14:28
问题 I'm looking for a (space) efficient implementation of an LCS algorithm for use in a C++ program. Inputs are two random access sequences of integers. I'm currently using the dynamic programming approach from the wikipedia page about LCS. However, that has O(mn) behaviour in memory and time and dies on me with out of memory errors for larger inputs. I have read about Hirschberg's algorithm, which improves memory usage considerably, Hunt-Szymanski and Masek and Paterson. Since it isn't trivial

LCS算法

匿名 (未验证) 提交于 2019-12-03 00:30:01
输入: 字符串 A和B,长度分别为n与m 输出: A和B最长公共子序列的长度t 步骤: 1、定义dp [i][j]:表示字符串序列A的前i个字符组成的序列Ax和字符串序列B的前j个字符组成的序列By之间的最长公共子序列L(i,j )的长度(m ,n分别为Ax和By的长度,i<=m,j<=n) 2、如果Ax [i] =By [j],那么Ax与By之间的最长公共子序列L( i,j )的最后一项一定是这个元素, 3、如果Ax[i] != By[j],设LCS(i-1,j-1)是L( i -1, j-1 )的最后一个元素,或者L(i-1,j-1)是空序列, 4、 初始值为: dp[0][j] = dp[i][0] = 0. : LCS(Longest Common Subsequences)最长公共子序列用一般的动态规划时间复杂度O(N^2) 文章来源: LCS算法

CSP2019模拟题一

匿名 (未验证) 提交于 2019-12-03 00:17:01
contest1 A. 最大子段和 描述 从这个序列中选出不相交的两个连续段,要求它们的和最大。 输入 第一行一个正整数 n n,表示序列长度。 接下来一行 个整数 a 1, a a ,表示题目描述中的序列。 输出 一行一个整数表示最大值。 样例 输入 7 2 -4 3 -1 2 -4 3 输出 7 提示 n<=1e5,a[i]<=1e9 solution 这道题实际上就是最长公共子序列的变形,只要从左边跑一边LCS,再从右边跑一边LCS,然后两边相加就可以了 下面呈上代码 来源:博客园 作者: 予林 链接:https://www.cnblogs.com/yulinss/p/11801445.html

Identify a common pattern [duplicate]

一曲冷凌霜 提交于 2019-12-02 02:41:54
问题 This question already has answers here : Find common substrings between two character variables (3 answers) Closed 3 years ago . Is there a (easy) possibility to identify a common pattern which two strings share? Here is a little example to make clear what I mean: I have two variables containing a string. Both include the same pattern ("ABC") and also some "noise". a <- "xxxxxxxxxxxABCxxxxxxxxxxxx" b <- "yyyyyyyyyyyyyyyyyyyyyyyABC" Lets say I don't know the common pattern and I want R to find

Identify a common pattern [duplicate]

半世苍凉 提交于 2019-12-02 02:02:05
This question already has an answer here: Find common substrings between two character variables 3 answers Is there a (easy) possibility to identify a common pattern which two strings share? Here is a little example to make clear what I mean: I have two variables containing a string. Both include the same pattern ("ABC") and also some "noise". a <- "xxxxxxxxxxxABCxxxxxxxxxxxx" b <- "yyyyyyyyyyyyyyyyyyyyyyyABC" Lets say I don't know the common pattern and I want R to find out that both strings contain "ABC". How can I do this? *edit The first example was maybe a bit to simplistic. Here is a

恶臭LCS

若如初见. 提交于 2019-12-01 07:06:17
今天(2019/10/13)考的题目,用学长写的能让人崩溃的LCS改编的 #include <iostream> #include <cstdio> #include <cstring> using namespace std; const int mod=100000000; const int maxn=5005; char a[maxn], b[maxn]; int f[2][maxn],g[2][maxn]; int main() { scanf("%s",a+1); scanf("%s",b+1); int n=strlen(a+1)-1, m=strlen(b+1)-1; g[1][0]=1; for(int j=0;j<=m;j++) _____1_____; for(int i=1;i<=n;i++) { int now=i&1,pre=now^1; for(int j=1; j<=m; j++) { f[now][j]=_____2_____; if(a[i]==b[j]) { f[now][j]=_____3_____; if(f[now][j]==f[pre][j-1]+1) g[now][j]=g[pre][j-1]; } else { g[now][j]=0; if(f[now][j]==f[pre][j-1]) g[now][j]-=g[pre][j-1