SnowflakeOA #30
Find the Maximum Length of a Good Subsequence I (LC 3176 :)
Estimated MediumJudge-ready
Topics (AI-labelled)SubsequencesHashing
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.
Input
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
Output the single integer required by the problem.
Example 1
Input:
6 2
1 1 2 3 2 1
Output:
5
Example 2
Input:
5 0
1 2 1 2 1
Output:
3
Example 3
Input:
1 0
1
Output:
1
Example notes
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.
Editorial
Loading solution…