2048

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 2048,2048 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.

鸭鸭最近迷上了一个类似2048的游戏。最初你有 个整数的集合 。这个集合 中的每个整数都是二的幂。 您可以使用该集合 执行任意数量(可能为零)的操作。 在每个操作中,从集合 中选择两个相等的整数,从集合 中移除它们,并将它们的和插入集合 中。 例如,如果集合 s={1,2,1,1,4,2,2} ,并且选择整数2和2,则集合s变成 {1,1,1,4,4,2} 。 如果数字2048在您的集合中,您就赢了。例如,如果集合 s={1024,512,512,4} ,您可以按如下方式获胜:选择512和512,您的集合s变成 {1024,1024,4} 。然后选择1024和1024,您的集合s变成 {2048,4} ,您就赢了。
你必须判断你是否能赢得这场比赛。
你必须回答 个独立的问题。

Input

第一行包含一个整数 q(1≤q≤100) 代表查询数。
每个查询的第一行包含一个整数 n (1≤n≤100) 代表集合 中的元素数量。
每个查询的第二行包含 个整数 S1,S2,…,Sn (1≤Si≤2的29次幂) 代表集合 的元素。
集合 的所有元素都是二的幂。

Output

对于每个查询,如果可以在集合 中获得数字2048,则输出“YES”,如果不行则输出“NO”。
只要输出的单词每个字母是对的都可,不在意大小写。

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
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a[105];
	int q;
	scanf("%d",&q);
	while(q--){
		int k=0;
		memset(a,0,sizeof(a));
		scanf("%d",&n);
		for(int i=1; i<=n; i++){
			int x;
			scanf("%d",&x);
			int ans=-1;
			while(x){
				x>>=1;
				ans++;
			}
			a[ans]++;
		}
		for(int i=0; i<=10; i++)	a[i+1]+=a[i]/2;
		if(a[11])	printf("YES\n");
		else	printf("NO\n");
	}
	return 0;
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值