[Linear] [dp] CH5E02 decision optimization

Face questions

To give you a n * m matrix requires that each row select a number, and the i-th row selection position a [i] must be greater than the first i-1 position of the selected row A [i-1], find the selected number of the sum of the number, a set of minimum output lexicographic a [1] to a [n].

range

1<=n<=m<=100

Thinking

First, the state is obvious dp

$f[i][j]=\max_{i-1<=k<j}f[i-1][k]+a[i][j]}$

Represent the maximum value and the time selected to the number of i-th row and j would choose this number. Complexity is $ (n ^ 3) $ O, although can be through, but in fact can also be optimized to find k ranges with j becomes larger and larger, it is provided a variable maxk during each cycle i, and j is changed every time , to use f [i-1] [j-1] is updated once maxk it.

This optimization is actually equivalent to a state represented by a maximum value and when the selected i-th row and j th number of this number will not necessarily selected, just like a change what transition equation

$f[i][j]=\max_{i-1<=k<j}f[i-1][k]+a[i][j]}$

 

$f[i][j]=\max_{i-1<=k<j}f[i-1][k]+a[i][j]$

As a good job in the end how, between individuals, but sometimes set up set up the first type more, I do not remember the second set @ _ @, or are thought as well.

Guess you like

Origin www.cnblogs.com/flashlizard/p/10992540.html