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
题意:给你一个序列,问你有多少个子序列的元素和为偶数。
直接看代码就懂,用到了全排的问题
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
const int inf=0x3f3f3f3f;
int mod=1e9+7;
int main()
{
freopen("azerah.in","r",stdin);
freopen("azerah.out","w",stdout);
int t;
scanf("%d",&t);
while(t--)
{
long long n;
cin>>n;
long long l=0,r=0,x;
for(int i=1; i<=n; i++)
{
cin>>x;
if(x%2==0)
l++;
else r++;
}
long long ans=1,sum=1;
for(int i=1; i<=l; i++)
{
ans*=2;
ans%=mod;
}
for(int i=1; i<r; i++)
{
sum*=2;
sum%=mod;
}
ans--;
sum--;
cout<<(sum+ans+sum*ans)%mod<<endl;
}
return 0;
}