A Dynamic Programming Framework for Combinatorial Optimization Problems on Graphs with Bounded Pathwidth