1. 程式人生 > >【Gym - 100923A】Por Costel and Azerah(思維水題)

【Gym - 100923A】Por Costel and Azerah(思維水題)

Por Costel and Azerah

Descriptions

給你n個數 問你,有多少個子序列 的和是偶數 

Example

Input
2
3
3 10 1
2
4 2
Output
3
3
題目連結 https://vjudge.net/problem/Gym-100923A   噁心死了  

freopen("azerah.in","r",stdin);
freopen("azerah.out","w",stdout);

必須加上 不然一直錯  卡了我1小時

直接看程式碼吧 挺水的

 

AC程式碼

#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define Mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define Maxn 1000010
using namespace std;
ll T,n;
int main()
{
    freopen("azerah.in","r",stdin);
    freopen("azerah.out","w",stdout);
    cin>>T;
    while(T--)
    {
        cin>>n;
        ll x;
        ll n1=0;//奇數個數
        ll n2=0;//偶數個數
        for(ll i=1; i<=n; i++)
        {
            cin>>x;
            if(x%2)
                n1++;
            else
                n2++;
        }
        ll s1=1;//奇數中的偶數子序列個數=2^(s1-1)-1
        ll s2=1;//偶數中的偶數子序列個數=2^s2-1
        //怕溢位,就一步一步迴圈吧
        for(ll i=1; i<=n2; i++)
        {
            s1*=2;
            s1%=Mod;
        }
        for(ll i=1; i<n1; i++)
        {
            s2*=2;
            s2%=Mod;
        }
        s1--;
        s2--;
        cout<<(s1+s2+s1*s2)%Mod<<endl;
    }
    return 0;
}