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

题目链接

题目大意

在一条数轴上住着 \(N\) 条狗和一个动物研究者 Bundle。Bundle 的坐标是 0,狗的坐标都是正整数,可能有多条狗住在同一个位置。每条狗都有一个颜色。Bundle 需要观测 \(K\) 条狗。要观测一条狗 Bundle 必须走到狗的住处,并且穿着和狗同色的衣服。Bundle 只能在家换衣服。试问 Bundle 至少要走多长的路程?注意:最后 Bundle 不必回到住处。

Constraints

  • 不超过 100 组测试数据
  • $ 1 \le N \le 1000 $
  • $ 1 \le K \le N $
  • Time limit: 30 s

分析

若 Bundle 最后必须回到住处,反而更好处理,并且复杂度可以做到 \(O(N \log C)\)\(C\) 表示狗的颜色总数。
思路:从左往右,把相邻的同色狗之间的距离放到一个小顶堆中。

在最后不必回到住处的条件下,貌似就只能 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.

这篇题解提供了另一种思路。

posted @ 2019-10-02 03:46  Pat  阅读(261)  评论(0编辑  收藏  举报