A successive approximation method in functional spaces for hierarchical optimal control problems and its application to learning