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

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
Output
YES
YES
NO
NO
YES
YES

Note

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.

题意:

给出一串数,所有的数全部都是2的次方。判断能否组成2048,里面的出现的数字可以由两个相同数字的和进行替换,比如2,2,8可以变成4,8。能输入YES,否则输出NO。

思维点:

首先要判断给的数据中有没有2048,要是存在2048就可以直接输出YES了,否则继续判断。

2048=2^11,1024=2^10,可以发现2的0次方一直加到2的10次方的和刚好是2047,如果说累加出来的sum大于2047,也就是说大于等于2048的话即可,

但是需要注意的是一旦遇到一个大于2048的,就不能进行累加。

 #include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h> typedef long long ll;
using namespace std; ll a[],b[]; int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
int flag=;
for(int i=;i<n;i++)
{
scanf("%lld",&a[i]);
if(a[i]==)
flag=;
}
if(flag)
printf("YES\n");
else
{
sort(a,a+n);
ll sum=;
int flag=;
for(int i=;i<n;i++)
{
if(a[i]>=)
continue;
sum+=a[i]; }
if(sum>=)
printf("YES\n");
else
printf("NO\n");
}
}
return ;
}

CodeForces-1221A-2048 Game-思维题的更多相关文章

  1. CF--思维练习-- CodeForces - 215C - Crosses(思维题)

    ACM思维题训练集合 There is a board with a grid consisting of n rows and m columns, the rows are numbered fr ...

  2. Codeforces 675C Money Transfers 思维题

    原题:http://codeforces.com/contest/675/problem/C 让我们用数组a保存每个银行的余额,因为所有余额的和加起来一定为0,所以我们能把整个数组a划分为几个区间,每 ...

  3. Codeforces 1090D - Similar Arrays - [思维题][构造题][2018-2019 Russia Open High School Programming Contest Problem D]

    题目链接:https://codeforces.com/contest/1090/problem/D Vasya had an array of n integers, each element of ...

  4. codeforces 1140D(区间dp/思维题)

    D. Minimum Triangulation time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  5. Codeforces 957 水位标记思维题

    A #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #def ...

  6. ACM思维题训练 Section A

    题目地址: 选题为入门的Codeforce div2/div1的C题和D题. 题解: A:CF思维联系–CodeForces -214C (拓扑排序+思维+贪心) B:CF–思维练习-- CodeFo ...

  7. codeforces ~ 1009 B Minimum Ternary String(超级恶心的思维题

    http://codeforces.com/problemset/problem/1009/B B. Minimum Ternary String time limit per test 1 seco ...

  8. 贪心/思维题 Codeforces Round #310 (Div. 2) C. Case of Matryoshkas

    题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0 ...

  9. C. Nice Garland Codeforces Round #535 (Div. 3) 思维题

    C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  10. CodeForces - 631C ——(思维题)

    Each month Blake gets the report containing main economic indicators of the company "Blake Tech ...

随机推荐

  1. Android中查看当前Activity是否销毁

    进入到Android-sdk中platform-tools目录 在命令行中执行以下命令 adb shell dumpsys activity>activity.txt 可以将当前的四大组件(Ac ...

  2. 欧拉降幂,基本计算定理——cf615D

    用基本算数定理求约数和的思想来计算, 首先用pi,ci来表示第i个质数,指数为i,然后对于每个pi,pi^2...都有指数为mul{(c_1+1)(c_2+1)(c_i-1+1)(c_i+1+1).. ...

  3. RichViewEdit

    RichViewEdit特殊操作 RichviewEdit 图文保存操作 首先要转换成stream后才能对RichviewEdit进行正确的读和写 function SaveRVFToField(rv ...

  4. 关于Kerberos协议流程的总结

    Kerberos协议工作原理分析 这里面借用一下师傅们的图来说明一下    Kerberos协议的流程大致如下(假设A要获取对Server B的访问权限) 第一步(KRB_AS_REQ) 这一步客户 ...

  5. 剑指offer——数组中出现次数超过一半的数字(c++)

    题目描述数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字.例如输入一个长度为9的数组{1,2,3,2,2,2,5,4,2}.由于数字2在数组中出现了5次,超过数组长度的一半,因此输出2.如 ...

  6. CF 1097D - Hello 2019 D题: Makoto and a Blackboard

    目录 Catalog Solution: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 Catalog Problem:传送门  Portal  原题目描述在最下面.  给一个数n ...

  7. CSS:CSS Float(浮动)

    ylbtech-CSS:CSS Float(浮动) 1.返回顶部 1. CSS Float(浮动) 什么是 CSS Float(浮动)? CSS 的 Float(浮动),会使元素向左或向右移动,其周围 ...

  8. jeecg接口开发及权限实现原理

    接口开发使用的框架 jeecg本身是基于 Spring MVC 框架搭建的,因此,使用 Spring MVC 框架的 RESTful API 功能来进行接口开发就是顺理成章的事了. 接口的拦截与鉴权 ...

  9. 拾遗:~/.zshrc 配置

    Tips: zsh 默认仅显示最近 16 条历史记录 $ # 等价于 history - :显示最近 条记录 $ history $ # 等价于 history - : 显示从第 条到最后 条,即是全 ...

  10. 第一周任务Largest Submatrix of All 1’s

    Largest Submatrix of All 1’s Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 9512   Ac ...