CF1221A.2048 Game

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are playing a variation of game 2048. Initially you have a multiset ss of nn integers. Every integer in this multiset is a power of two.

You may perform any number (possibly, zero) operations with this multiset.

During each operation you choose two equal integers from ss, remove them from ss and insert the number equal to their sum into ss.

For example, if s=1,2,1,1,4,2,2s = {1, 2, 1, 1, 4, 2, 2} and you choose integers 22 and 22, then the multiset becomes 1,1,1,4,4,2{1, 1, 1, 4, 4, 2}.

You win if the number 20482048 belongs to your multiset. For example, if s=1024,512,512,4s = {1024, 512, 512, 4} you can win as follows: choose 512512 and 512512, your multiset turns into 1024,1024,4{1024, 1024, 4}. Then choose 10241024 and 10241024, your multiset turns into 2048,4{2048, 4} and you win.

You have to determine if you can win this game.

You have to answer qq independent queries.

你正在玩一个 2048 游戏的变种。初始时,你有一个包含 nn 个整数的多重集 ss。该多重集中每个整数均为 22 的幂。

你可以对该多重集执行任意次数(可能为零次)的操作。

每次操作中,你从 ss 中选出两个相等的整数,将它们从 ss 中移除,并向 ss 中插入一个等于它们之和的数。

例如,若 s={1,2,1,1,4,2,2}s = \{1, 2, 1, 1, 4, 2, 2\},且你选择两个 22,则多重集变为 {1,1,1,4,4,2}\{1, 1, 1, 4, 4, 2\}。

当多重集 ss 中包含数字 20482048 时,你获胜。例如,若 s={1024,512,512,4}s = \{1024, 512, 512, 4\},你可以按如下方式获胜:先选择两个 512512,多重集变为 {1024,1024,4}\{1024, 1024, 4\};再选择两个 10241024,多重集变为 {2048,4}\{2048, 4\},从而获胜。

你需要判断是否能够赢得该游戏。

你需要回答 qq 个相互独立的查询。

输入格式

The first line contains one integer qq (1≤q≤1001 \le q \le 100) – the number of queries.

The first line of each query contains one integer nn (1≤n≤1001 \le n \le 100) — the number of elements in multiset.

The second line of each query contains nn integers s1,s2,…,sns_1, s_2, \dots, s_n (1≤si≤2291 \le s_i \le 2^{29}) — the description of the multiset. It is guaranteed that all elements of the multiset are powers of two.

第一行包含一个整数 qq(1≤q≤1001 \le q \le 100)—— 查询次数。

每个查询的第一行包含一个整数 nn(1≤n≤1001 \le n \le 100)—— 多重集中的元素个数。

每个查询的第二行包含 nn 个整数 s1,s2,…,sns_1, s_2, \dots, s_n(1≤si≤2291 \le s_i \le 2^{29})—— 多重集的描述。保证多重集中的所有元素均为 22 的幂。

输出格式

For each query print YES if it is possible to obtain the number 20482048 in your multiset, and NO otherwise.

You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).

对于每个查询,如果可以在你的多重集中得到数字 20482048,则输出 YES;否则输出 NO。

你可以以任意大小写形式输出每个字母(例如,字符串 yEs、yes、Yes 和 YES 均被视为肯定回答)。

输入输出样例

  • 输入#1

    6
    4
    1024 512 64 512
    1
    2048
    3
    64 512 2
    2
    4096 4
    7
    2048 2 2048 2048 2048 2048 2048
    2
    2048 4096

    输出#1

    YES
    YES
    NO
    NO
    YES
    YES

说明/提示

In the first query you can win as follows: choose 512512 and 512512, and ss turns into 1024,64,1024{1024, 64, 1024}. Then choose 10241024 and 10241024, and ss turns into 2048,64{2048, 64} and you win.

In the second query ss contains 20482048 initially.

在第一次查询中,你可以按如下方式获胜:选择 512512 和 512512,此时 ss 变为 1024,64,1024{1024, 64, 1024};然后选择 10241024 和 10241024,此时 ss 变为 2048,64{2048, 64},你获胜。

在第二次查询中,ss 初始即包含 20482048。

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

首页