From Contact Feasibility to Gait Sequence Optimization for Legged Robot Locomotion