Transient Optimization of Gas Pipeline for the Last Section via Dynamic Programming