CARVIEW |
Select Language
HTTP/2 200
date: Sat, 11 Oct 2025 13:20:00 GMT
content-type: text/html; charset=UTF-8
server: cloudflare
x-frame-options: DENY
x-content-type-options: nosniff
x-xss-protection: 1;mode=block
vary: accept-encoding
cf-cache-status: DYNAMIC
content-encoding: gzip
set-cookie: _csrf-frontend=545a65f023804748295f15148a8dbe99201674fa69268556bfcb49ea338d4aa8a%3A2%3A%7Bi%3A0%3Bs%3A14%3A%22_csrf-frontend%22%3Bi%3A1%3Bs%3A32%3A%22TshkCSRbWqPLmaUl-4URC8Wsbr_BdOYa%22%3B%7D; HttpOnly; Path=/
cf-ray: 98cea7035f4b7679-BLR
LCS O(n*m) + print all - Pastebin.com
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- string a, b;
- int n, m;
- int lcs[1001][1001]; //length of lcs
- set <string> set_lcs; //all distinct lcs
- void find_lcs(int n, int m, string s)
- {
- if (n == 0 or m == 0)
- {
- set_lcs.insert(s);
- return;
- }
- if (a[n-1] == b[m-1])
- {
- s = a[n-1] + s;
- find_lcs(n-1, m-1, s);
- }
- else
- {
- if (lcs[n-1][m] >= lcs[n][m-1])
- find_lcs(n-1, m, s);
- if (lcs[n-1][m] <= lcs[n][m-1])
- find_lcs(n, m-1, s);
- }
- }
- int main()
- {
- cin >> a >> b;
- n = a.size(), m = b.size();
- for (int i = 1; i<=n; i++)
- {
- for (int j = 1; j<=m; j++)
- {
- if (a[i-1] == b[j-1]) lcs[i][j] = lcs[i-1][j-1]+1;
- else lcs[i][j] = max(lcs[i-1][j], lcs[i][j-1]);
- }
- }
- find_lcs(n, m, "");
- cout << "LCS length is " << lcs[n][m] << endl
- << "LCS number is " << set_lcs.size() << endl;
- for (auto &s : set_lcs)
- cout << s << " ";
- }
Advertisement
Add Comment
Please, Sign In to add comment
-
⭐✅ MAKE $2500 IN 15 MIN⭐⭐⭐ 4
JavaScript | 1 sec ago | 0.24 KB
-
⭐ Free Crypto Method ✅ NEVER SEEN BEFORE ⭐⭐⭐
JavaScript | 4 sec ago | 0.24 KB
-
⭐✅ MAKE $2500 IN 15 MIN⭐⭐⭐ 6
JavaScript | 7 sec ago | 0.24 KB
-
⭐⭐⭐Profit Method⭐⭐
Java | 11 sec ago | 0.10 KB
-
⭐✅ Exploit 2500$ in 15 Minutes⭐⭐⭐ C
JavaScript | 13 sec ago | 0.24 KB
-
✅⭐ Make huge profits on trading ✅ NEVER SEEN...
JavaScript | 16 sec ago | 0.24 KB
-
⭐✅ Exploit 2500$ in 15 Minutes⭐⭐⭐ 3
JavaScript | 18 sec ago | 0.24 KB
-
⭐⭐⭐Swapzone.io Glitch (Working)⭐⭐
Java | 22 sec ago | 0.10 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand