GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — other_algorithm/LCSAndDynamicArray at master · inuyashaw/other_algorithm

Expand file tree

/

LCSAndDynamicArray

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
41 lines (38 loc) · 1.11 KB
/

LCSAndDynamicArray

Copy path

File metadata and controls

41 lines (38 loc) · 1.11 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//用滚动数组实现lcs(从二维数组求lcs的代码中可看出,一个坐标的值仅依赖于横纵减一的两行)
//该方法只能求出lcs的长度,求不了具体substring
#include<iostream>
#include<vector>
#include<string.h>
#include<algorithm>
using namespace std;
int LongestCommentSubsequence(const char* str1, const char* str2)
{
int str1Length = (int)strlen(str1);
int str2Length = (int)strlen(str2);
const char* p1 = str1 - 1;
const char* p2 = str2 - 1;
//vector<vector<int> > vec(2, vector<int>(str2Length));
vec[2][str2Length + 1];
memset(vec, 0 ,sizeof(vec));
int i, j;
for(i = 1; i <= str1Length; i++)
{
for(j = 1;j <= str2Length; j++)
{
if(p1[i] == p2[j])
vec[i%2][j] = vec[(i-1)%2][j-1] + 1;
else
vec[i%2][j] = max(vec[(i-1)%2][j],vec[i%2][j-1]);
}
}
return vec[str1Length%2][str2Length];
}
int main(int argc, char* argv[])
{
const char* str1 = "jslfsdmgldsm";
const char* str2 = "kldjsflsdsdkfklsd";
string str;
int result = LongestCommentSubsequence(str1, str2);
std::cout<< "Longest Comment Subsequence:" << result <<std::endl;
return 0;
}
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.