A

来源:互联网 发布:sql 多列分组求和汇总 编辑:程序博客网 时间:2024/06/06 14:20

Por Costel the Pig has received a royal invitation to the palace of the Egg-Emperor of Programming, Azerah. Azerah had heard of the renowned pig and wanted to see him with his own eyes. Por Costel, having arrived at the palace, tells the Egg-Emperor that he looks “tasty”. Azerah feels insulted (even though Por Costel meant it as a compliment) and, infuratied all the way to his yolk, threatens to kill our round friend if he doesn’t get the answer to a counting problem that he’s been struggling with for a while

Given an array of numbers, how many non-empty subsequences of this array have the sum of their numbers even ? Calculate this value mod (Azerah won’t tell the difference anyway)

Help Por Costel get out of this mischief!

Input
The file azerah.in will contain on its first line an integer , the number of test cases. Each test has the following format: the first line contains an integer (the size of the array) and the second line will contain integers (), separated by single spaces.

It is guaranteed that the sum of over all test cases is at most

Output
The file azerah.out should contain lines. The -th line should contain a single integer, the answer to the -th test case.

Example
Input
2
3
3 10 1
2
4 2
Output
3
3
题意: 给你n个数 问你,有多少个子序列 的和是偶数
解:even+even=odd
odd+ odd=odd
odd 子集情况 ,2^n-1;
even 2^(n-1)-1;

// 1.看数据范围,相乘时会不会爆范围。// 2.1-10小数据不是很难就全测。// 3.是否初始化#include<iostream>#include<cstdio>using namespace std;#define ll long longconst ll N = (ll)1e9 + 7;ll solve(ll a, ll b){    ll ans =1;    while (b)    {        if (b & 1)            ans =(ans* a)%N;        a =(a*a)%N;        b >>= 1;    }    return ans%N;}int main(){    freopen("azerah.in", "r", stdin);    freopen("azerah.out","w",stdout);    ll t, n, i, j;    while (cin >> t)    {        while (t--)        {            scanf("%lld", &n);            ll even = 0, odd = 0,a,s1=0,s2=0,s3=0;            while (n--)            {                scanf("%lld", &a);                if (a & 1) even++;                else odd++;                //puts("****");            }            if (odd >= 1)                s1 = solve(2, odd) - 1;            if (even >= 2)                s2 = solve(2, even - 1) - 1;            s3 = s1*s2;            cout << (s1 + s2 + s3)%N << endl;        }    }    return 0;}