class MoveSplitMerge implements IDistanceMetric {

    @Override
    public double distance(double[] a, double[] b) {
        int n = a.length;
        int m = b.length;
        double[][] cost = new double[n][m];

        // Initialization.
        cost[0][0] = Math.abs(a[0] - b[0]);
        for (int i = 1; i < n; i++) {
            cost[i][0] = cost[i - 1][0] + c(a[i], a[i - 1], b[0]);
        }
        for (int j = 1; j < m; j++) {
            cost[0][j] = cost[0][j - 1] + c(b[j], a[0], b[j - 1]);
        }

        // Dynamic programming.
        for (int i = 1; i < n; i++) {
            for (int j = 1; j < m; j++) {
                double costMove = cost[i - 1][j - 1] + Math.abs(a[i] - b[j]);
                double cost2 = cost[i - 1][j] + c(a[i], a[i - 1], b[j]);
                double cost3 = cost[i][j - 1] + c(b[j], a[i], b[j - 1]);
                cost[i][j] = Math.min(costMove, Math.min(cost2, cost3));
            }
        }

        return cost[n - 1][m - 1];
    }

    public  MoveSplitMerge(double c);

}