calculating the minimum penalty
for ( i = 1 ; i <= m ; i ++ ) { for ( j = 1 ; j <= n ; j ++ ) { if ( x [ i - 1 ] == y [ j - 1 ] ) { dp [ i , j ] = dp [ i - 1 , j - 1 ] ; } else { dp [ i , j ] = Math . Min ( Math . Min ( dp [ i - 1 , j - 1 ] + pxy , dp [ i - 1 , j ] + pgap ) , dp [ i , j - 1 ] + pgap ) ; } } }