cswork / OA打开练习工作台

SnowflakeOA #30

Find the Maximum Length of a Good Subsequence I (LC 3176 :)

估计中等可在线判题

考点(AI 标注)子序列哈希计数

Choose the longest subsequence in which the number of adjacent pairs with unequal values is at most k. Elements of the original array may be skipped.

输入格式

The first line contains n k, and the second line contains n values. Original constraints: 1≤n≤500, 1≤value≤10⁹, 0≤k≤min(n,25).

输出格式

Output the single integer required by the problem.

样例 1

输入:

6 2
1 1 2 3 2 1

输出:

5

样例 2

输入:

5 0
1 2 1 2 1

输出:

3

样例 3

输入:

1 0
1

输出:

1

样例说明

The answers to the three public examples are, in order: 5; 3; 1. The examples were rechecked by independent enumeration, state search, or direct simulation.