2048Game

Just do a title of a 2048game

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,2}s={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,4}s={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.

Input

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

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

The second line of each query contains nn integers s1,s2,…,sns1,s2,…,sn (1≤si≤2291≤si≤229) — the description of the multiset. It is guaranteed that all elements of the multiset are powers of two.

Output

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).

Example

the Input

. 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

the Output

YES
YES
NO
NO
YES
YES

Note

the In The First Query you CAN win AS Follows: the Choose 512512 and 512512 , and SS turns INTO 1024,64,1024} {} {1024,64,1024. the Then the Choose 10,241,024 and 10,241,024, and turns INTO {SS 2048,64 2048,64} {} and you win.

the In The SECOND Query the contains SS . 20482048 initially
meaning of the questions summarize: to give you a number that is a power of 2, the number of columns in the same number can be added to each other, the same number of columns of numbers after the addition, it also can be added. He asked that the series does not have a transformation may occur in 2048.

I began to think of how to quickly identify a number of columns in any number can make up a given value, but this is too much trouble, and he gave us the power of 2, then think of a method of using the number of columns, fast and convenient

 1 #include<iostream>
 2 
 3 using namespace std;
 4 typedef long long ll;
 5 
 6 int log2(ll a) {
 7     int count = 0;
 8     while (1) {
 9         if (a >>= 1)
10             count++;
11         else
12             break;
13     }
14     return count;
15 }
16 
17 intmain () {
 18 is      int Q, n-, TEMP; // indicates the number of how many the number of groups and the number of each group 
. 19      Long  Long INPUT;
 20 is      CIN >> Q;
 21 is      the while (q - ) {
 22 is          int A [ 14 ] {= 0 };
 23 is          CIN >> n-;
 24          the while (N-- ) {
 25              CIN >> INPUT;
 26 is              TEMP = Iog2 (INPUT);
 27              IF (TEMP> . 11 )
 28                  Continue ;
 29             a[temp]++;
30             while (a[temp] == 2) {
31                 if(temp!=11)
32                 a[temp] = 0;
33                 a[++temp]++;
34             }
35             
36         }
37         if (a[11] >0) {
38             cout << "YES" << endl;
39         }else
40             cout << "NO" << endl;
41     }
42     return 0;
43 }
View Code

Probably mediated kind

Guess you like

Origin www.cnblogs.com/zlszls3113373723/p/11700771.html