首页 > 试题广场 >

Coincidence

[编程题]Coincidence
  • 热度指数:11336 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
Find a longest common subsequence of two strings.

输入描述:
First and second line of each input case contain two strings of lowercase character a…z. There are no spaces before, inside or after the strings. Lengths of strings do not exceed 100.


输出描述:
For each case, output k – the length of a longest common subsequence in one line.
示例1

输入

abcd
cxbydz

输出

2
头像 大内高手
发表于 2020-03-18 12:23:23
状态转移方程为: 当s1[i] = s2[j]时: 当s1[i] != s2[j]时: // runtime: 4ms // space: 504K // complexity: O(m*n) #include <iostream> #include <cstring& 展开全文
头像 robin呀
发表于 2022-03-03 22:56:50
Coincidence(找到两个字符串的最长公共子串)(上海交通大学) 关键字:动态规划、最长公共字 关键需要处理好边界点,不然计算比较麻烦 ">#include<vector> #include<string> using namespace std; //P236 习题1 展开全文
头像 在考古的小鱼干很有气魄
发表于 2023-03-09 09:14:30
#include <bits/stdc++.h> #define MAX 100 using namespace std; int main() { int dp[MAX][MAX], i, j; string s1, s2; cin >> s1 &g 展开全文
头像 BrianWu
发表于 2021-07-06 20:03:20
/*描述Find a longest common subsequence of two strings.输入描述:First and second line of each input case contain two strings of lowercase character a…z. The 展开全文
头像 牛客440904392号
发表于 2024-09-30 17:31:34
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String 展开全文
头像 粉詹眉
发表于 2024-03-23 23:03:24
#include <iostream> #include <cstring> using namespace std; const int N=110; int f[N][N];//f[i][j]:a[1]~a[i]和b[1]~b[j]的最长公共子序列长度 char a[N 展开全文
头像 牛客206588308号
发表于 2025-02-28 18:35:31
#include<iostream> #include<cstring> using namespace std; const int maxn=100; char str1[maxn]; char str2[maxn]; int dp[maxn][maxn]; int ma 展开全文
头像 笑川不吃香菜
发表于 2024-03-12 16:50:27
#include <bits/stdc++.h> using namespace std; int main() { string s1, s2; cin >> s1 >> s2; if (s1 == "" || s2 展开全文
头像 nzxkc
发表于 2022-02-11 23:53:43
LCS,套模板 ```cpp #include<iostream> #include<cstring> using namespace std; //LCS,这里只要求长度 int main(){     string s1,s2;   展开全文
头像 辣椒味的糖葫芦
发表于 2023-03-19 15:10:46
s0 = input() s1 = input() m, n = len(s0), len(s1) dp = [[0 for i in range(n + 1)] for j in range(m + 1)]#dp是递推,大小需要多个1 for i in range(m): for j in 展开全文