azerah.in / azerah.out

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

给你一个序列,问你有多少个子序列的元素和为偶数。

水dp。分别记f(i)为前i位元素和为偶数的子序列数,g(i)为前i位元素和为奇数的子序列数。瞎几把转移一下就行了。

#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
#define MOD 1000000007ll
int T,a[1000010],n;
ll f[1000010],g[1000010];
int main()
{
// freopen("a.in","r",stdin);
freopen("azerah.in","r",stdin);
freopen("azerah.out","w",stdout);
scanf("%d",&T);
for(;T;--T)
{
memset(f,0,sizeof(f));
memset(g,0,sizeof(g));
scanf("%d",&n);
for(int i=1;i<=n;++i)
scanf("%d",&a[i]);
if(a[1]%2)
g[1]=1;
else
f[1]=1;
for(int i=2;i<=n;++i)
if(a[i]%2)
{
f[i]=(g[i-1]+f[i-1])%MOD;
g[i]=((f[i-1]+g[i-1])%MOD+1ll)%MOD;
}
else
{
f[i]=((f[i-1]*2ll)%MOD+1ll)%MOD;
g[i]=(g[i-1]*2ll)%MOD;
}
printf("%d\n",f[n]);
}
return 0;
}

【动态规划】Gym - 100923A - Por Costel and Azerah的更多相关文章

  1. 【Gym - 100923A】Por Costel and Azerah(思维水题)

    Por Costel and Azerah Descriptions 给你n个数 问你,有多少个子序列 的和是偶数 Example Input 233 10 124 2 Output 33 题目链接 ...

  2. 【Heap-dijkstra】Gym - 100923B - Por Costel and the Algorithm

    algoritm.in / algoritm.out Even though he isn't a student of computer science, Por Costel the pig ha ...

  3. 【找规律】Gym - 100923L - Por Costel and the Semipalindromes

    semipal.in / semipal.out Por Costel the pig, our programmer in-training, has recently returned from ...

  4. 【分块打表】Gym - 100923K - Por Costel and the Firecracker

    semipal.in / semipal.out Por Costel the pig, our programmer in-training, has recently returned from ...

  5. 【数形结合】Gym - 100923I - Por Costel and the Pairs

    perechi3.in / perechi3.out We don't know how Por Costel the pig arrived at FMI's dance party. All we ...

  6. 【并查集】Gym - 100923H - Por Costel and the Match

    meciul.in / meciul.out Oberyn Martell and Gregor Clegane are dueling in a trial by combat. The fight ...

  7. 【带权并查集】Gym - 100923H - Por Costel and the Match

    裸题. 看之前的模版讲解吧,这里不再赘述了. #include<cstdio> #include<cstring> using namespace std; int fa[10 ...

  8. 【Gym - 100923I】Por Costel and the Pairs(思维题)

    Por Costel and the Pairs Descriptions 有T组测试样例 有n个男的,n个女的,第i个人都有为当前一个大小为i的懒惰值,当一男一女懒惰值的乘积<=n他们就就可以 ...

  9. Gym-100923A-Por Costel and Azerah(DP)

    链接: https://vjudge.net/problem/Gym-100923A 题意: Por Costel the Pig has received a royal invitation to ...

随机推荐

  1. Expect使用小记

    By francis_hao    May 31,2017   本文翻译了部分Expect的man手册,只选取了个人常用的功能,因此并不完善.   Expect是一个可以和交互式程序对话的程序 概述 ...

  2. CentOS ninimal 安装后没有桌面-yellowcong

    昨天,安装Centos后,发现没有桌面,主要是没有安装桌面环境导致 的这个问题,我们需要做的第一步是,安装一个桌面(GNOME Desktop,命令:yum groupinstall -y " ...

  3. [cdoj 1344]树状数组区间加等差数列

    题目链接:http://acm.uestc.edu.cn/#/problem/show/1344 区间加等差数列本质上就是区间修改区间查询,本来想用线段树做,结果这个题就是卡空间和时间……不得已学了区 ...

  4. 固定width但是有间隔

    <!DOCTYPE > <html> <head> <title></title> <meta name="name&quo ...

  5. lucene、solr、nutch三者的关系

    lucene是一个做搜索用的类库. nutch和solr都是基于lucene的,二者都是可直接运行的应用程序: 直接在业务上使用lucene的倒是不太多见. solr主要提供了建立索引(用户可以直接p ...

  6. Sass、Ruby、Nodejs、gulp

    1.Sass文件就是普通的文本文件,不过其文件后缀名有两种,一种为“.sass”:另一种为“.scss”.我们一般用“.scss”就好,至于这两种文件扩展名的区别在于“.sass”是Sass语言文件的 ...

  7. HDU1847 Good Luck in CET-4 Everybody!

    大学英语四级考试就要来临了,你是不是在紧张的复习?也许紧张得连短学期的ACM都没工夫练习了,反正我知道的Kiki和Cici都是如此.当然,作为在 考场浸润了十几载的当代大学生,Kiki和Cici更懂得 ...

  8. bzoj 1861 splay

    就是裸地splay,然后自己写的不是特别好,tle了,最近时间比较紧迫,有时间了改下,在此记录 另附转载pascal AC代码最下面 /******************************** ...

  9. 通过jQuery实现轮播效果

    HTML <div class="wrap"> <div id="slide"> <ul class="list&quo ...

  10. 转:布局【ViewGroup】

    转: http://www.cnblogs.com/leehyuan/p/3389527.html 像素单位的变化:是用dip,而不是px,主要用于宽高的设置 在Android中支持的描述大小区域的类 ...