Dynamic nested sampling: an improved algorithm for parameter estimation and evidence calculation