308481: CF1527E. Partition Game
Memory Limit:256 MB
Time Limit:3 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Partition Game
题意翻译
$hater$扔给你一个长度为$n$序列,定义其中一个连续子序列$t$的代价为: $$ cost(t)=\sum_{x\in set(t)}last(x)−first(x) $$ 其中$set(t)$表示该子序列的元素集合,$last(x)$表示$x$在该子序列中最后一次出现的位置,$first(x)$表示$x$在该子序列中第一次出现的位置。 也就是说一个连续子序列的贡献为对于其中每种元素最后一次出现的位置与第一次出现的位置的下标差的和。 现在你要把原序列划分成$k$个连续子序列,求最小代价和。 其中$1\leq n\leq35000,1\leq k\leq min(n,100),1\leq a_i \leq n$。题目描述
You are given an array $ a $ of $ n $ integers. Define the cost of some array $ t $ as follows: $ $cost(t) = \sum_{x \in set(t) } last(x) - first(x), $ $ </p><p>where $ set(t) $ is the set of all values in $ t $ without repetitions, $ first(x) $ , and $ last(x) $ are the indices of the first and last occurrence of $ x $ in $ t $ , respectively. In other words, we compute the distance between the first and last occurrences for each distinct element and sum them up.</p><p>You need to split the array $ a $ into $ k $ consecutive segments such that each element of $ a$ belongs to exactly one segment and the sum of the cost of individual segments is minimum.输入输出格式
输入格式
The first line contains two integers $ n $ , $ k $ ( $ 1 \le n \le 35\,000 $ , $ 1 \le k \le \min(n,100) $ ). The second line contains $ n $ integers $ a_1, a_2, \ldots, a_n $ ( $ 1 \le a_i \le n $ ).
输出格式
Output the minimum sum of the cost of individual segments.
输入输出样例
输入样例 #1
7 2
1 6 6 4 6 6 6
输出样例 #1
3
输入样例 #2
7 4
5 5 5 5 2 3 3
输出样例 #2
1