  We use a suite of cosmological simulations to study the
mass-concentration-redshift relation, $c({\rm M},z)$, of dark matter halos. Our
simulations include standard $\Lambda$-cold dark matter (CDM) models, and
additional runs with truncated power spectra, consistent with a thermal warm
dark matter (WDM) scenario. We find that the mass profiles of CDM and WDM halos
are self-similar and well approximated by the Einasto profile. The $c({\rm
M},z)$ relation of CDM halos is monotonic: concentrations decrease with
increasing virial mass at fixed redshift, and decrease with increasing redshift
at fixed mass. The mass accretion histories (MAHs) of CDM halos are also
scale-free, and can be used to infer concentrations directly. These results do
not apply to WDM halos: their MAHs are not scale-free because of the
characteristic scale imposed by the power-spectrum suppression. Further, the
WDM $c({\rm M},z)$ relation is non-monotonic: concentrations peak at a mass
scale dictated by the truncation scale, and decrease at higher and lower
masses. We show that the assembly history of a halo can still be used to infer
its concentration, provided that the total mass of its progenitors is
considered (the "collapsed mass history"; CMH), rather than just that of its
main ancestor. This exploits the scale-free nature of CMHs to derive a simple
scaling that reproduces the mass-concentration-redshift relation of both CDM
and WDM halos over a vast range of halo masses and redshifts. Our model
therefore provides a robust account of the mass, redshift, cosmology and power
spectrum dependence of dark matter halo concentrations.
