THIS PART OF CODE IS SAME AS BELOW POST . IT FILLS dp [ , ] https : www . geeksforgeeks . org / longest - repeating - subsequence / OR the code mentioned above .
int n = str . Length , i , j ; int [ , ] dp = new int [ n + 1 , n + 1 ] ; for ( i = 0 ; i <= n ; i ++ ) for ( j = 0 ; j <= n ; j ++ ) dp [ i , j ] = 0 ; for ( i = 1 ; i <= n ; i ++ ) for ( j = 1 ; j <= n ; j ++ ) if ( str [ i - 1 ] == str [ j - 1 ] && i != j ) dp [ i , j ] = 1 + dp [ i - 1 , j - 1 ] ; else dp [ i , j ] = Math . Max ( dp [ i , j - 1 ] , dp [ i - 1 , j ] ) ;