【DP 好题】Kick Start 2019 Round C Catch Some

Topic Link

Subject to the effect

In a number of home $ N $ shaft and a dog animal researcher Bundle. Coordinate Bundle is 0, the coordinates of the dog are positive integers, there may be multiple dogs live in the same position. Each dog has a color. $ K $ Bundle need to observe the dog. To observe a dog Bundle dog must come to the residence, and the dog and wearing the same color clothes. Bundle only at home to change clothes. Bundle least ask how long to go away? Note: The last Bundle does not have to return to the residence.

Constraints

  • No more than 100 groups of test data
  • $ 1 \ N \ le $ 1000
  • $ 1 \ K \ N $
  • Time limit: 30 s

analysis

If Bundle must eventually return to the residence, it is better to deal with, and can be done complexity $ O (N \ log C) $, $ C $ represents the total number of colors of the dog.
Ideas: from left to right, the distance between adjacent same color into a small top dog pile.

In the last residence without having to return to the conditions, it looks like the only DP.

Let dp[i][j][k] denotes the minimum amount of walk needed to observe j dogs such that Bundle has either observed or has decided she'll not observe dogs of colors 1 to i and k is a boolean denoting if we have chosen the last color in the first i colors.

This problem solution offers another idea.

Guess you like

Origin www.cnblogs.com/Patt/p/11616676.html