CF2153A.Circle of Apple Trees

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are nn apple trees arranged in a circle. Each tree bears exactly one apple, and the beauty of the apple on the ii-th tree is given by bib_i for all 1≤i≤n1\le i\le n. You start in front of tree 11.

At each tree, you may choose to either eat the apple or skip it. After making your choice, you move to the next tree: from tree ii, you move to tree i+1i+1 for 1≤i≤n−11 \le i \le n - 1, and from tree nn, you move back to tree 11. This process continues indefinitely as you move through the trees in a cycle.

However, you have a special condition: you may only eat an apple if its beauty is strictly greater than the beauty of the last apple you ate. For example, if b=[2,1,2,3]b = [2, 1, 2, 3] and you eat the apple on tree 11 (beauty 22), you cannot eat the apples on trees 22 and 33 because their beauties are not greater than 22. However, you may eat the apple on tree 44 since b4=3>2b_4 = 3 \gt 2.

Note that you are allowed to skip an apple when you first encounter it, and you can choose to eat it later on a subsequent cycle.

Your task is to determine the maximum number of apples you can eat if you make optimal decisions on when to eat or skip each apple.

有 nn 棵苹果树围成一个圆圈。每棵树上恰好结一个苹果,第 ii 棵树上的苹果的美丽值为 bib_i(其中 1≤i≤n1 \le i \le n)。你从第 11 棵树前开始。

在每一棵树处,你可以选择吃掉该苹果,或跳过它。做出选择后,你将移动到下一棵树:从第 ii 棵树出发,当 1≤i≤n−11 \le i \le n - 1 时,你移动到第 i+1i+1 棵树;而从第 nn 棵树出发时,你回到第 11 棵树。这一过程无限持续,你将不断绕圈经过这些树。

但你有一个特殊限制:仅当当前苹果的美丽值严格大于你上一次吃掉的苹果的美丽值时,你才可以吃掉它。
例如,若 b=[2,1,2,3]b = [2, 1, 2, 3],且你吃了第 11 棵树上的苹果(美丽值为 22),那么你无法吃第 22 棵和第 33 棵树上的苹果,因为它们的美丽值均不大于 22;但你可以吃第 44 棵树上的苹果,因为 b4=3>2b_4 = 3 > 2。

注意:你可以在第一次经过某棵苹果树时跳过该苹果,并在后续某一轮循环中再选择吃掉它。

你的任务是:在对每个苹果的吃与跳过作出最优决策的前提下,求出你能吃到的苹果数量的最大值。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤5001 \le t \le 500). The description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤1001 \le n\le 100) — the number of apple trees.

The second line of each test case contains nn integers b1,b2,…,bnb_1, b_2, \ldots, b_n (1≤bi≤n1\le b_i\le n) — the beauty of the apples on the trees.

Note that there are no constraints on the sum of nn over all test cases.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤5001 \le t \le 500)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤1001 \le n\le 100)—— 苹果树的数量。

每个测试用例的第二行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \ldots, b_n(1≤bi≤n1\le b_i\le n)—— 各棵树上苹果的美丽值。

注意:对所有测试用例的 nn 之和不作任何限制。

输出格式

For each test case, output a single integer representing the maximum number of apples you can eat.

对于每个测试用例,输出一个整数,表示你能吃到的苹果的最大数量。

输入输出样例

  • 输入#1

    3
    4
    2 2 2 2
    5
    1 4 5 1 2
    6
    5 4 2 1 2 3

    输出#1

    1
    4
    5

说明/提示

In the first test case, since all apples have the same beauty, no matter which apple you eat first, you cannot eat any others afterward. Hence, the maximum number of apples that you can eat is 11.

In the second test case, you can eat four apples as follows:

  • At tree 11, skip the apple.
  • At tree 22, skip the apple.
  • At tree 33, skip the apple.
  • At tree 44, eat the apple (beauty 11).
  • At tree 55, eat the apple (beauty 22).
  • At tree 11, skip the apple. You are not allowed to eat the apple as its beauty (b1=1b_1 = 1) is not greater than the beauty of the last apple you ate (b5=2b_5 = 2).
  • At tree 22, eat the apple (beauty 44).
  • At tree 33, eat the apple (beauty 55).

It can be proven that it is not possible to eat all five apples; hence, the maximum number of apples that you can eat is 44.

在第一个测试用例中,由于所有苹果的美丽值均相同,无论你先吃哪一个苹果,之后都无法再吃其他苹果。因此,你能吃的苹果的最大数量为 11。

在第二个测试用例中,你可以按如下方式吃掉四个苹果:

  • 在第 11 棵树处,跳过该苹果。
  • 在第 22 棵树处,跳过该苹果。
  • 在第 33 棵树处,跳过该苹果。
  • 在第 44 棵树处,吃掉该苹果(美丽值为 11)。
  • 在第 55 棵树处,吃掉该苹果(美丽值为 22)。
  • 在第 11 棵树处,跳过该苹果。你不能吃它,因为它的美丽值(b1=1b_1 = 1)不大于你上一次所吃苹果的美丽值(b5=2b_5 = 2)。
  • 在第 22 棵树处,吃掉该苹果(美丽值为 44)。
  • 在第 33 棵树处,吃掉该苹果(美丽值为 55)。

可以证明,不可能吃掉全部五个苹果;因此,你能吃的苹果的最大数量为 44。

输入解题思路,AI测评打分。不知道怎么写?

首页