  We develop for charmed hadron production in relativistic heavy-ion collisions
a comprehensive coalescence model that includes an extensive set of $s$ and
$p$-wave hadronic states as well as the strict energy-momentum conservation,
which ensures the boost invariance of the coalescence probability and the
thermal limit of the produced hadron spectrum. By combining our hadronization
scheme with an advanced Langevin-hydrodynamics model that incorporates both
elastic and inelastic energy loss of heavy quarks inside the dynamical
quark-gluon plasma, we obtain a successful description of the
$p_\mathrm{T}$-integrated and differential $\Lambda_c/D^0$ and $D_s/D^0$ ratios
measured at RHIC and the LHC. We find that including the effect of radial flow
of the medium is essential for describing the enhanced $\Lambda_c/D^0$ ratio
observed in relativistic heavy-ion collisions. We also find that the puzzling
larger $\Lambda_c/D^0$ ratio observed in Au+Au collisions at RHIC than in Pb+Pb
collisions at the LHC is due to the interplay between the effects of the QGP
radial flow and the charm quark transverse momentum spectrum at hadronization.
Our study further suggests that charmed hadrons have larger sizes in medium
than in vacuum.
