B. Luntik and Subsequences

time limit per test

1 second

memory limit per test

256 megabytes

Luntik came out for a morning stroll and found an array a of length n. He calculated the sum s of the elements of the array (s=∑ni=1ai). Luntik calls a subsequence of the array a nearly full if the sum of the numbers in that subsequence is equal to s−1.

Luntik really wants to know the number of nearly full subsequences of the array a. But he needs to come home so he asks you to solve that problem!

A sequence x is a subsequence of a sequence y if x can be obtained from y by deletion of several (possibly, zero or all) elements.

Input

The first line contains a single integer t (1≤t≤1000) --- the number of test cases. The next 2⋅t lines contain descriptions of test cases. The description of each test case consists of two lines.

The first line of each test case contains a single integer n (1≤n≤60) --- the length of the array.

The second line contains n integers a1,a2,...,an (0≤ai≤109) --- the elements of the array a.

Output

For each test case print the number of nearly full subsequences of the array.

Example

Input

Copy

复制代码
5
5
1 2 3 4 5
2
1000 1000
2
1 0
5
3 0 2 1 1
5
2 1 0 3 0

Output

Copy

复制代码
1
0
2
4
4

Note

In the first test case, s=1+2+3+4+5=15, only (2,3,4,5) is a nearly full subsequence among all subsequences, the sum in it is equal to 2+3+4+5=14=15−1.

In the second test case, there are no nearly full subsequences.

In the third test case, s=1+0=1, the nearly full subsequences are (0) and () (the sum of an empty subsequence is 0).

解题说明:此题是一道模拟题,其实就是找出数列中1和0的个数,找规律能发现结果就是1的个数乘以2^(0的个数)。

cpp 复制代码
#include<stdio.h>
int main()
{
	long long int t, a[65], i;
	scanf("%lld", &t);
	a[0] = 0;
	for (i = 1; i <= 61; i++)
	{
		a[i] = 1 + a[i - 1] * 2;
	}
	while (t--)
	{
		long long int s = 0, ans = 0, b = 0, c = 0, n, x;
		scanf("%lld", &n);
		for (i = 0; i < n; i++)
		{
			scanf("%lld", &x);
			if (x == 1)
			{
				b++;
			}
			if (x == 0)
			{
				c++;
			}
		}
		if (b)
		{
			ans = b + a[c] * b;
		}
		printf("%lld\n", ans);
	}
	return 0;
}
相关推荐
Fcy6487 小时前
算法基础详解(4)双指针算法
开发语言·算法·双指针
zk_ken7 小时前
优化图像拼接算法思路
算法
xwz小王子7 小时前
Nature Communications从结构到功能:基于Kresling折纸的多模态微型机器人设计
人工智能·算法·机器人
luj_17687 小时前
从R语言想起的,。。。
服务器·c语言·开发语言·经验分享·算法
计算机安禾8 小时前
【数据结构与算法】第29篇:红黑树原理与C语言模拟
c语言·开发语言·数据结构·c++·算法·visual studio
生信研究猿8 小时前
94. 二叉树的中序遍历 (二叉树遍历整理)
数据结构·算法
挂科边缘8 小时前
image-restoration-sde复现,图像修复,使用均值回复随机微分方程进行图像修复,ICML 2023
算法·均值算法·ir-sde·扩散模块图像修复
2301_822703208 小时前
开源鸿蒙跨平台Flutter开发:血氧饱和度数据降噪:基于滑动窗口的滤波算法优化-利用动态列队 (Queue) 与时间窗口平滑光电容积脉搏波 (PPG)
算法·flutter·华为·开源·harmonyos
Vin0sen8 小时前
算法-线段树与树状数组
算法
sycmancia8 小时前
QT——计算器核心算法
开发语言·qt·算法