此题的题意很明确,就是求最长公共子序列: #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<queue> using namespace std; ][]; ]; int main() { ],ter[],fir[]; int n,i,j; while(scanf("%d",&n)!=EOF) { mem…
反恐训练营 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3567 Accepted Submission(s): 843 Problem Description 当今国际反恐形势很严峻,特别是美国"9.11事件"以后,国际恐怖势力更是有恃无恐,制造了多起骇人听闻的恐怖事件.基于此,各国都十分担心恐怖势力会对本国社会造成的不稳定,…
反恐训练营 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3040    Accepted Submission(s): 693 Problem Description 当今国际反恐形势非常严峻,特别是美国"9.11事件"以后,国际恐怖势力更是有恃无恐,制造了多起骇人听闻的恐怖事件.基于此,各国都十分操心恐怖势力会对本国社会…
先上题目: 反恐训练营 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2783    Accepted Submission(s): 634 Problem Description 当今国际反恐形势很严峻,特别是美国“9.11事件”以后,国际恐怖势力更是有恃无恐,制造了多起骇人听闻的恐怖事件.基于此,各国都十分担心恐怖势力会对本国社会造…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1243 d[i][j] 代表第i 个字符与第 j 个字符的最大的得分.,, 最大公共子序列变形 #include <cstring> #include <cstdlib> #include <cstdio> #include <iostream> #include <algorithm> using namespace std; +; char s[max…
<span style="color:#993399;">/* By yuan 2014/6/21 At nwpu.xf 1041.最长公共子序列 时限:1000ms 内存限制:200000K 总时限:3000ms 描写叙述 一个给定序列的子序列是在该序列中删去若干元素后得到的序列.确切地说,若给定序列X=<x1, x2,-, xm>,则还有一序列Z=<z1, z2,-, zk>是X的子序列是指存在一个严格递增的下标序列 <i1, i2,-,…
LCS. /* 1243 */ #include <cstdio> #include <cstring> #include <cstdlib> #define MAXN 2025 #define MAXM 256 char type[MAXM]; int point[MAXM]; char bullet[MAXN]; char kbfz[MAXN]; int dp[MAXN][MAXN]; int n; int min(int a, int b) { return a&…
题目链接:反恐训练营 题意:本质上是求最大公共子序列,然后加上一个权值 分析:见代码 //公共子序列问题 //dp[i][j]表示前s1的前i个与s的前j个匹配得到的最大公共子序列 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ],dp[][],f[][] ; ],s2[]; void out(int x,int y) { ||y==) return ; ) { ,…
反恐训练营 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3450    Accepted Submission(s): 802 Problem Description 当 今国际反恐形势很严峻,特别是美国“9.11事件”以后,国际恐怖势力更是有恃无恐,制造了多起骇人听闻的恐怖事件.基于此,各国都十分担心恐怖势力会对 本国社会造成的不稳…
题目 输出最长公共字串 #define maxn 200010 int wa[maxn],wb[maxn],wv[maxn],ws[maxn]; int cmp(int *r,int a,int b,int l) {return r[a]==r[b]&&r[a+l]==r[b+l];}//yuan lai zhi qian ba zhe li de l cuo dang cheng 1 le ... void da(int *r,int *sa,int n,int m) { int i,j…
题目: 给定两个字符串X,Y,求二者最长的公共子串,例如X=[aaaba],Y=[abaa].二者的最长公共子串为[aba],长度为3. 子序列是不要求连续的,字串必须是连续的. 思路与代码: 1.简单思想: 遍历两个字符串X.Y,分别比较X的字串与Y的字串,求出最长的公共字串. 设X长度为m,Y长度为n,最长公共字串长度为len,则时间复杂度为O(m*n*len),空间复杂度为O(1) #include <iostream> #include <vector> using nam…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159 Common Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 37551    Accepted Submission(s): 17206 Problem Description A subsequence of…
传送门 Description Alex has two sequences a1,a2,...,an and b1,b2,...,bm. He wants find a longest common subsequence that consists of consecutive values in increasing order. Input There are multiple test cases. The first line of input contains an integer…
Common Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 18387    Accepted Submission(s): 7769 Problem Description A subsequence of a given sequence is the given sequence with some el…
题目链接:https://vjudge.net/contest/124428#problem/A 题目大意:给出两个字符串,求其最长公共子序列的长度. 最长公共子序列算法详解:https://blog.csdn.net/hrn1216/article/details/51534607     (其中的图解很详细)   根据图解理解下面代码 #include<cstdio> #include <string> #include<cstring> #include<i…
Problem Description A subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence X = <x1, x2, ..., xm> another sequence Z = <z1, z2, ..., zk> is a subsequence of X if there exists a stri…
Advanced Fruits Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3340    Accepted Submission(s): 1714Special Judge Problem Description The company "21st Century Fruits" has specialized in cr…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159 Problem Description 给定序列的子序列是给定的序列,其中有一些元素(可能没有)被遗漏. 给定一个序列X = <x1,x2,...,xm>如果存在严格递增的序列<i1,i2,...,则另一个序列Z = <z1,z2,...,zk>是X的子序列. ...,ik>的索引,使得对于所有j = 1,2,...,k,xij = zj. 例如,Z = <a,…
题意: 两个字符串,判断最长公共子序列的长度. 思路: 直接看代码,,注意边界处理 代码: char s1[505], s2[505]; int dp[505][505]; int main(){ while(scanf("%s%s",s1,s2)!=EOF){ int l1=strlen(s1); int l2=strlen(s2); mem(dp,0); dp[0][0]=((s1[0]==s2[0])?1:0); rep(i,1,l1-1) if(s1[i]==s2[0]) dp…
1. 问题描述 子串应该比较好理解,至于什么是子序列,这里给出一个例子:有两个母串 cnblogs belong 比如序列bo, bg, lg在母串cnblogs与belong中都出现过并且出现顺序与母串保持一致,我们将其称为公共子序列.最长公共子序列(Longest Common Subsequence,LCS),顾名思义,是指在所有的子序列中最长的那一个.子串是要求更严格的一种子序列,要求在母串中连续地出现.在上述例子的中,最长公共子序列为blog(cnblogs,belong),最长公共子…
Blue Jeans Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14113   Accepted: 6260 Description The Genographic Project is a research partnership between IBM and The National Geographic Society that is analyzing DNA from hundreds of thousa…
package tek; Java算法——求出两个字符串的最长公共字符串 /** * @Title: 问题:有两个字符串str1和str2,求出两个字符串中最长公共字符串. * @author 匹夫(在YW的数据基础上再次延伸) * @date 2017年4月19日 下午8:08:37 */ public class Demo1 { /* //减0 个字符 内循环1次 k2.substring(0, 7);//外循环第1次_内循环第1次 //减一个字符 内循环2次 k2.substring(0,…
http://acm.hdu.edu.cn/showproblem.php?pid=1423 在前一道题的基础上多了一次筛选 要选出一个最长的递增数列 lower_bound()函数很好用,二分搜索找出满足ai>k的ai最小指针 还有upper_bound() 头文件#include<algorithm> 比如求长度为n的数组a中k的个数:upper_bound(a,a+n,k)-lower_bound(a,a+n,k) int 放在main函数里面声明会出现程序崩溃,放在全局就没有问题…
http://acm.hdu.edu.cn/showproblem.php?pid=1403 Longest Common Substring Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3068    Accepted Submission(s): 1087 Problem Description Given two string…
传送门 题目大意: 将两个字符串对齐(只包含ACGT,可以用'-'占位),按照对齐分数表(参见题目)来计算最后的分数之和,输出最大的和. 例如:AGTGATG 和 GTTAG ,对齐后就是(为了表达对齐,这里我用m表示'-') AGTGATG mGTTAmG 题目分析: 首先看出这道题与LCS有关,下面来考虑转移: 当t1[i]==t2[j]时,和LCS一样,\(dp[i][j] = dp[i-1][j-1]+score[t1[i]][t2[j]]\) 当t1[i]!=t2[j]时,唯一不同的是…
A subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence X = <x1, x2, ..., xm> another sequence Z = <z1, z2, ..., zk> is a subsequence of X if there exists a strictly increasing sequ…
链接1:http://blog.csdn.net/x_xiaoge/article/details/7376220 链接2:http://blog.csdn.net/x_xiaoge/article/details/7376217 链接3:http://www.cnblogs.com/huangxincheng/archive/2012/11/11/2764625.html LCS 1.动态规划法:见链接1.3 int LCS( string leftString, string rightSt…
用一个特殊字符将两个字符串连接起来,然后找最大的height,而且要求这两个相邻的后缀的第一个字符不能在同一个字符串中. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; + ; char s[maxn]; int n; int sa[maxn], rank[maxn], height[maxn]; int t[maxn], t2[maxn], c[maxn];…
''' merge two configure files, basic file is aFile insert the added content of bFile compare to aFile for example, 'bbb' is added content ----------------------------------------------------------- a file content | b file content | c merged file cont…
题目: 就不贴了吧···如题: 题解: 后缀自动机模版题:没啥好说的···· 代码: #include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> #include<ctime> #include<cctype> #include<cstring> #include<string> #include<algorithm>…