Fast Exact Algorithms For Optimization Problems In Resource Allocation And Switched Linear Systems