QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 1024 MB 總分: 100

#11228. 熊猫先生与纸带

统计

熊猫先生非常喜欢彩色的纸条。有一天,他的朋友买给他一条很长的纸条,上面有 $N$ 个颜色,从左到右依次为 $C_0, C_1, \dots, C_{N-1}$。不幸的是,熊猫先生只喜欢颜色各不相同的纸条,所以他的朋友打算把这条纸条切成若干部分,然后要么取其中一部分,要么将其中两部分拼接起来,形成一个新的纸条 $A_0, A_1, \dots, A_{K-1}$。为了让熊猫先生高兴,新纸条必须只包含互不相同的颜色,这意味着不存在 $0 \le i < j < K$ 使得 $A_i = A_j$。他的朋友还希望新纸条尽可能长。请找出新纸条可能的最大长度。

输入格式

输入的第一行给出一个整数 $T$,表示测试用例的数量。接下来是 $T$ 个测试用例。每个测试用例的第一行是一个整数 $N$,表示原始纸条中颜色的数量。接下来一行包含 $N$ 个整数 $C_0, C_1, \dots, C_{N-1}$,表示颜色。

输出格式

对于每个测试用例,输出一行 “Case #x: y”,其中 $x$ 是测试用例编号(从 1 开始),$y$ 是新纸条可能的最大长度。

数据范围

  • $1 \le T \le 20$
  • $1 \le N \le 1000$
  • $1 \le C_i \le 10^5$

样例

样例输入 1

3
3
1 2 3
8
3 1 2 1 6 1 2 5
3
1 1 1

样例输出 1

Case #1: 3
Case #2: 5
Case #3: 1

说明

Case #1: 切成 2 部分:[1] [2 3],然后将这两部分拼接起来形成纸条:[1 2 3];或者直接切成一部分:[1 2 3],此时无需拼接。

Case #2: 切成 3 部分:[3] [1 2] [6 1 2 5],然后将第一部分和第三部分拼接起来形成纸条:[3 6 1 2 5]。

Case #3: 切成 3 部分:[1] [1] [1],然后取其中一部分形成新纸条:[1]。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.