pub fn dp_core<T: OrDistElement>(v1: &[T], v2: &[T], rewrite_cost: usize) -> usize {
    let (n1, n2) = (v1.len(), v2.len());
    let mut dp = Array2::zeros((n1 + 1, n2 + 1));
    for i in 0..n1 + 1 {
        dp[[i, 0]] = i;
    }
    for i in 0..n2 + 1 {
        dp[[0, i]] = i;
    }

    for i1 in 0..n1 {
        for i2 in 0..n2 {
            let cost = if v1[i1] == v2[i2] { 0 } else { rewrite_cost };
            dp[[i1 + 1, i2 + 1]] = min(
                min(dp[[i1, i2 + 1]] + 1, dp[[i1 + 1, i2]] + 1),
                dp[[i1, i2]] + cost,
            );
        }
    }
    dp[[n1, n2]]
}
/// The core function of dynamic programming.
/// 
/// The value of dp[[i+1, j+1]] is the minimum value of
/// ```
/// dp[[i+1, j  ]] + 1
/// dp[[i  , j+1]] + 1
/// dp[[i  , j  ]] + rewrite_cost
/// ```
The core function of dynamic programming.
The core function of dynamic programming .
pub fn dp_core<T: OrDistElement>(v1: &[T], v2: &[T], rewrite_cost: usize) -> usize {
    let (n1, n2) = (v1.len(), v2.len());
    let mut dp = Array2::zeros((n1 + 1, n2 + 1));
    for i in 0..n1 + 1 {
        dp[[i, 0]] = i;
    }
    for i in 0..n2 + 1 {
        dp[[0, i]] = i;
    }
    for i1 in 0..n1 {
        for i2 in 0..n2 {
            let cost = if v1[i1] == v2[i2] { 0 } else { rewrite_cost };
            dp[[i1 + 1, i2 + 1]] = min(
                min(dp[[i1, i2 + 1]] + 1, dp[[i1 + 1, i2]] + 1),
                dp[[i1, i2]] + cost,
            );
        }
    }
    dp[[n1, n2]]
}
pub fn dp_core < T : OrDistElement > ( v1 : & [ T ] , v2 : & [ T ] , rewrite_cost : usize ) -> usize { let ( n1 , n2 ) = ( v1 . len ( ) , v2 . len ( ) ) ; let mut dp = Array2 :: zeros ( ( n1 + 1 , n2 + 1 ) ) ; for i in 0 .. n1 + 1 { dp [ [ i , 0 ] ] = i ; } for i in 0 .. n2 + 1 { dp [ [ 0 , i ] ] = i ; } for i1 in 0 .. n1 { for i2 in 0 .. n2 { let cost = if v1 [ i1 ] == v2 [ i2 ] { 0 } else { rewrite_cost } ; dp [ [ i1 + 1 , i2 + 1 ] ] = min ( min ( dp [ [ i1 , i2 + 1 ] ] + 1 , dp [ [ i1 + 1 , i2 ] ] + 1 ) , dp [ [ i1 , i2 ] ] + cost , ) ; } } dp [ [ n1 , n2 ] ] }
The core function of dynamic programming.
The core function of dynamic programming .
v1
&[T]
v2
&[T]
rewrite_cost
usize
v1
&[T]
v2
&[T]
rewrite_cost
usize