def _accumulated_cost_matrix(ac):
    """Fast computation of accumulated cost matrix using cost matrix.

    Parameters
    ----------
    ac: nd-array
        Given cost matrix c, ac = acc_initialization(...), ac[1:, 1:] = c.

    Returns
    -------
        The accumulated cost matrix.
    """
    for i in range(ac.shape[0] - 1):
        for j in range(ac.shape[1] - 1):
            ac[i + 1, j + 1] += min(ac[i, j + 1], ac[i + 1, j], ac[i, j])
    return ac