A method of characteristics and invariant imbedding for distributed control problems