###### 编程介的小学生

2017-01-29 12:32 阅读 856

# The Cow Lineup

Farmer John’s N cows (1 <= N <= 100,000) are lined up in a row.Each cow is labeled with a number in the range 1…K (1 <= K <=10,000) identifying her breed. For example, a line of 14 cows might have these breeds:

``````1 5 3 2 5 1 3 4 4 2 5 1 2 3
``````

Farmer John’s acute mathematical mind notices all sorts of properties of number sequences like that above. For instance, he notices that the sequence 3 4 1 3 is a subsequence (not necessarily contiguous) of the sequence of breed IDs above. FJ is curious what is the length of the shortest possible sequence he can construct out of numbers in the range 1..K that is NOT a subsequence of the breed IDs of his cows. Help him solve this problem.

• Line 1: Two integers, N and K

• Lines 2..N+1: Each line contains a single integer that is the breed ID of a cow. Line 2 describes cow 1; line 3 describes cow 2; and so on.

• Line 1: Two integers, N and K

• Lines 2..N+1: Each line contains a single integer that is the breed ID of a cow. Line 2 describes cow 1; line 3 describes cow 2; and so on.

14 5
1
5
3
2
5
1
3
4
4
2
5
1
2
3

3

• 点赞
• 写回答
• 关注问题
• 收藏
• 复制链接分享