  In this paper we study optimal control problems in Wasserstein spaces, which
are suitable to describe macroscopic dynamics of multi-particle systems. The
dynamics is described by a parametrized continuity equation, in which the
Eulerian velocity field is affine w.r.t. some variables. Our aim is to minimize
a cost functional which includes a control norm, thus enforcing a \emph{control
sparsity} constraint. More precisely, we consider a nonlocal restriction on the
total amount of control that can be used depending on the overall state of the
evolving mass. We treat in details two main cases: an instantaneous constraint
on the control applied to the evolving mass and a cumulative constraint, which
depends also on the amount of control used in previous times. For both
constraints, we prove the existence of optimal trajectories for general cost
functions and that the value function is viscosity solution of a suitable
Hamilton-Jacobi-Bellmann equation. Finally, we discuss an abstract Dynamic
Programming Principle, providing further applications in the Appendix.
