Maximum Subarray Sum Dynamic Programming And Optimal Control With State Space