Dynamic programming for 2-D discrete linear systems