A - Por Costel and Azerah Gym - 100923A

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
题意:意思就是给出一组数,找到任意组合令和为偶数的序列的个数。例如第一组 3 10 1
中和为偶数的序列分别是 10,3+1,3+1+10 第二组:4,2,4+2。是一道dp题,因为有奇数偶数两个变量所以是二维dp,0代表奇数,1代表偶数。

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
long long mod=1e9+7;
long long dp[1000005][2];
int main()
{
    freopen("azerah.in","r",stdin);
    freopen("azerah.out","w",stdout);
    int t;
    scanf("%d",&t);
    while(t--)
    {

        long long n;
        scanf("%lld",&n);
        dp[0][0]=1;
        dp[0][1]=0;
        for(long long i=1; i<=n; i++)
        {
            long long k;
            scanf("%lld",&k);
            if(k%2==1)
            {

                dp[i][0]=(dp[i-1][1]+dp[i-1][0])%mod;//奇数加偶数等于偶数
                dp[i][1]=(dp[i-1][0]+dp[i-1][1])%mod;//偶数加偶数等于偶数
            }
            else
            {

                dp[i][0]=2*dp[i-1][0]%mod;//奇数加奇数等于偶数
                dp[i][1]=2*dp[i-1][1]%mod;//偶数加偶数等于偶数
            }

        }

        printf("%lld\n",dp[n][0]-1);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值