"The sub-exam" little odd adventure

topic

[Memory Limit: $ 256 MiB $] [Time limit: $ 1000 ms $]
[ Stdio] [Title Type: Traditional] [ Evaluation method: Text Comparison]


 

answer

Do title ideas

The most basic things do not explain, it must be $ dp $ a class of problems.

Then start thinking about $ dp $ defined.

Examination defined: $ dp [i] [j] $: as well as the number before the $ I $ position, picking up a total of $ J $ a chest.

Clearly, however, this $ dp $ defined loopholes, examination room can get $ 50pts $ worship today I have the gift of a down

Correct

First, consider the simple $ dp $:

Defined three-dimensional $ dp [i] [j] [k] $: $ I $ pushed to the second position, and the front one is taken $ J $, has picked up a total of $ k $ a chest.

Needless to say, like turn, $ O (N ^ 2) $ of $ dp $, and space ......

Considered to simplify the processing, a simplified state:

$ Dp [i] $: $ I $ of taking some bits, the maximum benefit is in front and some legal solutions

Then turn form: $ dp [i] = Max (dp [j]) + a [i] * k ^ x, j \ in [i-M + 1, i) $

But this formula there is a problem, how many chest in front of the election we do not know, it can be said in front of the state in fact have an impact on the back of state

That is the $ x $ parameters we do not know, that we may also need to take a one-dimensional to record how many have the chest.

Then space on the bombing.

Here the use of a very clever way, we pushed backwards state, like turn:

$$dp[i]=kMax\{dp[j]\}+a[i],j\in (i,i+M-1]$$

It cleverly Where?

The previous analysis: how to take a front impact would be back

Then we doing exactly the opposite: how to take back the state will not affect the previous state.

Finally, it became a simple $ dp $ plus sliding window (ie monotone queue) optimization

No time code of code ah ......

 

Guess you like

Origin www.cnblogs.com/MachineryCountry/p/11728842.html