longest Common Subsequence
int [ , ] dpl = new int [ N + 2 , M + 2 ] ; for ( int i = 1 ; i <= N ; i ++ ) { for ( int j = 1 ; j <= M ; j ++ ) { if ( A [ i - 1 ] == B [ j - 1 ] ) dpl [ i , j ] = dpl [ i - 1 , j - 1 ] + 1 ; else dpl [ i , j ] = Math . Max ( dpl [ i - 1 , j ] , dpl [ i , j - 1 ] ) ; } } int LCS = dpl [ N , M ] ;