longest common subsequence
C++
int maxSubsequenceSubstring(char x[], char y[],
int n, int m)
{
int dp[MAX][MAX];
// Initialize the dp[][] to 0.
for (int i = 0; i <= m; i++)
for (int j = 0; j <= n; j++)
dp[i][j] = 0;
// Calculating value for each element.
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
// If alphabet of string X and Y are
// equal make dp[i][j] = 1 + dp[i-1][j-1]
if (x[j - 1] == y[i - 1])
dp[i][j] = 1 + dp[i - 1][j - 1];
// Else copy the previous value in the
// row i.e dp[i-1][j-1]
else
dp[i][j] = dp[i][j - 1];
}
}
// Finding the maximum length.
int ans = 0;
for (int i = 1; i <= m; i++)
ans = max(ans, dp[i][n]);
return ans;
}
Also in C++:
- Title
- calling a method on an object c++
- Category
- C++
- Title
- what is time complexity of min_element()
- Category
- C++
- Title
- pairs in c++
- Category
- C++
- Title
- how to switch to another branch in git
- Category
- C++
- Title
- c++ typeid get type name
- Category
- C++
- Title
- c++ class template
- Category
- C++
- Title
- strchr function in c++
- Category
- C++
- Title
- generate random double c++
- Category
- C++
- Title
- variant hold type
- Category
- C++
- Title
- check for bst
- Category
- C++
- Title
- count a character in a string c++
- Category
- C++
- Title
- c++ raw string
- Category
- C++
- Title
- opencv compile c++
- Category
- C++
- Title
- c++ string^ to char*
- Category
- C++
- Title
- caesar cipher program in c++
- Category
- C++
- Title
- qt graphics scene map cursor position
- Category
- C++
- Title
- c++ switch case statement
- Category
- C++
- Title
- c++ get last element in vector
- Category
- C++
- Title
- traverse map c++
- Category
- C++
- Title
- fast input output in c++
- Category
- C++
- Title
- c++ files
- Category
- C++
- Title
- how to run a c++ program in the background
- Category
- C++
- Title
- iostream library in cpp
- Category
- C++
- Title
- max in c++
- Category
- C++
- Title
- pop_back
- Category
- C++
- Title
- convert GLFWwindow* to IntPtr
- Category
- C++
- Title
- how to load from files C++
- Category
- C++
- Title
- bitset c++
- Category
- C++
- Title
- How to check if a triangular cycle exists in a graph
- Category
- C++
- Title
- namespace c++
- Category
- C++
- Title
- delete 2d dynamic array c++
- Category
- C++
- Title
- how to include seld declared header file in c++
- Category
- C++
- Title
- insert elements in array in c++11
- Category
- C++
- Title
- stack c++
- Category
- C++
- Title
- cpp loop through object
- Category
- C++
- Title
- making random numbers in c++
- Category
- C++
- Title
- root to leaf path print
- Category
- C++
- Title
- % operator in c++
- Category
- C++
- Title
- rand c++
- Category
- C++
- Title
- c++ replace n substrings
- Category
- C++
- Title
- substitution failure is not an error
- Category
- C++
- Title
- accumulate in cpp
- Category
- C++
- Title
- c++ for loops
- Category
- C++
- Title
- power c++
- Category
- C++
- Title
- euler's totient function c++
- Category
- C++
- Title
- how to get the prime number in c++ where time complexity is 0(log n)
- Category
- C++
- Title
- hashmap in c++
- Category
- C++
- Title
- subarray sum in c++
- Category
- C++
- Title
- c++ declare variable
- Category
- C++
- Title
- variadic templates
- Category
- C++
- Title
- Arrays hackerrank solution in c++
- Category
- C++
- Title
- iterative preorder traversal
- Category
- C++
- Title
- switch case sinax c++
- Category
- C++
- Title
- flake8 max line length
- Category
- C++
- Title
- binary tree search
- Category
- C++
- Title
- c++ excel blank cells
- Category
- C++
- Title
- c++ program to find gcd of 3 numbers
- Category
- C++
- Title
- c++ function to find length of array
- Category
- C++
- Title
- pointers in cpp
- Category
- C++
- Title
- ue4 c++ enum
- Category
- C++
- Title
- c++ how to skip the last element of vector
- Category
- C++
- Title
- COnvert string to char * C++
- Category
- C++
- Title
- c++ allocate dynamic with initial values
- Category
- C++
- Title
- find in vector in c++
- Category
- C++
- Title
- set c++
- Category
- C++
- Title
- how to read and write in a file c++
- Category
- C++
- Title
- pass by reference c++
- Category
- C++
- Title
- quick sort predefined function in c++
- Category
- C++
- Title
- dynamic 2d array c++
- Category
- C++
- Title
- properties of a set c++
- Category
- C++
- Title
- how to take input in C++ in coding
- Category
- C++
- Title
- c++ try
- Category
- C++
- Title
- c++ do you not inherit constructor
- Category
- C++
- Title
- first prime numbers
- Category
- C++
- Title
- clear console c++
- Category
- C++
- Title
- calling by reference and pointers c++
- Category
- C++
- Title
- how to grab all of user input c++
- Category
- C++
- Title
- Convert binary tree to a doubly linked list
- Category
- C++
- Title
- clear file before writing c++
- Category
- C++
- Title
- c++ class constructor
- Category
- C++
- Title
- two elements with difference K in c++
- Category
- C++
- Title
- c++ dereference a pointer
- Category
- C++
- Title
- calculate factorial
- Category
- C++
- Title
- error: redefinition of ‘class Customer’
- Category
- C++
- Title
- vector stl c++
- Category
- C++
- Title
- object slicing in c++
- Category
- C++
- Title
- how to declare a vector in c++
- Category
- C++
- Title
- c++ how to add something at the start of a vector
- Category
- C++
- Title
- simple timer arduino blynk library error
- Category
- C++
- Title
- function declerations in C++
- Category
- C++
- Title
- compare string c++
- Category
- C++
- Title
- c++ declare char
- Category
- C++
- Title
- nan c++ example
- Category
- C++
- Title
- c++ ambigous error
- Category
- C++
- Title
- index string c++
- Category
- C++
- Title
- retu7rn this c++
- Category
- C++
- Title
- cloud hosting
- Category
- C++
- Title
- how to output to console c++
- Category
- C++
- Title
- how to print eachh chars in string data type in c++
- Category
- C++
- Title
- get data from terminal c++
- Category
- C++