Maximize [ length ( X ) / 2 ^ ( XOR ( X , Y ) ) ] by choosing substrings X and Y from string A and B respectively | C # program for the above approach ; Function to find the length of the longest common substring of the string X and Y ; LCSuff [ i ] [ j ] stores the lengths of the longest common suffixes of substings ; Itearate over strings A and B ; If first row or column ; If matching is found ; Otherwise , if matching is not found ; Finally , return the resultant maximum value LCS ; Driver Code ; Function Call
using System ; using System . Collections . Generic ; class GFG { static int lcsubtr ( char [ ] a , char [ ] b , int length1 , int length2 ) { int [ , ] dp = new int [ length1 + 1 , length2 + 1 ] ; int max = 0 ; for ( int i = 0 ; i <= length1 ; ++ i ) { for ( int j = 0 ; j <= length2 ; ++ j ) { if ( i == 0 j == 0 ) { dp [ i , j ] = 0 ; } else if ( a [ i - 1 ] == b [ j - 1 ] ) { dp [ i , j ] = dp [ i - 1 , j - 1 ] + 1 ; max = Math . Max ( dp [ i , j ] , max ) ; } else { dp [ i , j ] = 0 ; } } } return max ; } public static void Main ( ) { string m = "0110" ; string n = "1101" ; char [ ] m1 = m . ToCharArray ( ) ; char [ ] m2 = n . ToCharArray ( ) ; Console . Write ( lcsubtr ( m1 , m2 , m1 . Length , m2 . Length ) ) ; } }