Compute the permanents of a matrix