CF2228A.Marisa Steals Reimu's Takeout

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

The Darkness Brought In by Swallowstone Naturalis Historia

— Dateless Bar "Old Adam"

Marisa is a girl of integrity who always helps others safeguard their belongings. Over a period of nn days, she comes each day to take one of Reimu's takeouts. The ii-th takeout is described by its deliciousness value — an integer wiw_i (0≤wi≤20\le w_i\le 2), forming a sequence ww of length nn.

Marisa has a special fondness for the number 33. She can perform the following operation zero or more times:

  • Select a non-empty subsequence∗^{\text{∗}} of ww whose sum is divisible by 33, and remove the elements of the subsequence from ww.

Determine the maximum number of operations Marisa can perform.

∗^{\text{∗}}A sequence aa is a subsequence of a sequence bb if aa can be obtained from bb by the deletion of several (possibly, zero or all) element from arbitrary positions.

由燕石带来的黑暗——《自然史》

——无日期酒吧“老亚当”

玛莉莎是一位正直的女孩,总是帮助他人守护物品。在连续 nn 天中,她每天都会来取走灵梦的一份外卖。第 ii 份外卖以其美味值(一个整数 wiw_i,满足 0≤wi≤20 \le w_i \le 2)来描述,从而构成一个长度为 nn 的序列 ww。

玛莉莎对数字 33 情有独钟。她可以执行以下操作零次或多次:

  • 选取 ww 的一个非空子序列∗^{\text{∗}},其元素之和能被 33 整除,并将该子序列中的所有元素从 ww 中移除。

请确定玛莉莎最多能执行多少次这样的操作。

∗^{\text{∗}} 序列 aa 是序列 bb 的一个子序列,当且仅当 aa 可通过从 bb 的任意位置删除若干个(可能为零个或全部)元素而得到。

输入格式

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 second line contains nn integers w1,w2,…,wnw_1, w_2, \ldots, w_n (0≤wi≤20\leq w_i \leq 2), denoting the deliciousness values of the takeouts.

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

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

第二行包含 nn 个整数 w1,w2,…,wnw_1, w_2, \ldots, w_n(0≤wi≤20\leq w_i \leq 2),表示各外卖的美味值。

输出格式

For each test case, output the maximum number of operations Marisa can perform.

对于每个测试用例,输出 Marisa 能执行的最大操作次数。

输入输出样例

  • 输入#1

    3
    4
    0 0 0 0
    3
    1 2 0
    5
    1 2 1 2 1

    输出#1

    4
    2
    2

说明/提示

In the first test case, Marisa can perform four operations: $$[\underline{0},0,0,0]\to[\underline{0},0,0]\to[\underline{0},0]\to[\underline{0}]\to [].$$

In the second test case, Marisa can perform two operations: $$[\underline{1},\underline{2},0]- \gt [\underline{0}]- \gt [].$$

In the third test case, Marisa can perform two operations: $$[\underline{1},2,1,\underline{2},1]- \gt [\underline{2},1,\underline{1}]- \gt [1].$$

在第一个测试用例中,Marisa 可以执行四次操作:

[0‾,0,0,0]→[0‾,0,0]→[0‾,0]→[0‾]→[].[\underline{0},0,0,0]\to[\underline{0},0,0]\to[\underline{0},0]\to[\underline{0}]\to[].

在第二个测试用例中,Marisa 可以执行两次操作:

[1‾,2‾,0]→[0‾]→[].[\underline{1},\underline{2},0]\to[\underline{0}]\to[].

在第三个测试用例中,Marisa 可以执行两次操作:

[1‾,2,1,2‾,1]→[2‾,1,1‾]→[1].[\underline{1},2,1,\underline{2},1]\to[\underline{2},1,\underline{1}]\to[1].

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

首页