On nonconvex differential inclusions whose state is constrained in the closure of an open set. Applications to dynamic programming