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. barba.js 优化页面跳转用户体验

    barba.js 原理就是在a页面中显示b页面的内容,样式为刷新,给用户以页面跳转后无刷新体验,注意样式命名,ab页面引用的样式和js要相同 可以在页面之间创建良好的转换,增强用户的体验. 减少HTT ...

  2. es6+最佳入门实践(6)

    6.Symbol用法 6.1.什么是Symbol? Symbol是es6中一种新增加的数据类型,它表示独一无二的值.es5中我们把数据类型分为基本数据类型(字符串.数字.布尔.undefined.nu ...

  3. .NET之特性和属性(转)

    1. 引言 attribute是.NET框架引入的有一技术亮点,因此我们有必要花点时间走进一个发现attribute登堂入室的入口.因为.NET Framework中使用了大量的定制特性来完成代码约定 ...

  4. [USACO1.3]虫洞

    Luogu链接 题目描述 农夫约翰爱好在周末进行高能物理实验的结果却适得其反,导致N个虫洞在农场上(2<=N<=12,n是偶数),每个在农场二维地图的一个不同点. 根据他的计算,约翰知道他 ...

  5. 【UVALive4685-Succession】树形DP

    http://acm.hust.edu.cn/vjudge/problem/14338 题意:给定一棵树,每个点有一个值,让你选择k个点,并且这k个点是连在一起的(从任意一个点出发,可以遍历完所有选择 ...

  6. 【洛谷 P1653】 猴子 (并查集)

    题目链接 没删除调试输出,原地炸裂,\(80\)->\(0\).如果你要问剩下的\(20\)呢?答:数组开小了. 这题正向删边判连通性是很不好做的,因为我们并不会并查集的逆操作.于是可以考虑把断 ...

  7. bzoj 2749 杂题

    我们可以发现,phi(x)与x相比,相当于x的每个质因子-1后再分解质因数,添加到现有的质因子中,比如质因子13相当于将13变成12,然后分解成2*2*3,再将2的质数+2,3的指数+1,除了质因子2 ...

  8. [ Openstack ] Openstack-Mitaka 高可用之 环境初始化

    目录 Openstack-Mitaka 高可用之 概述    Openstack-Mitaka 高可用之 环境初始化    Openstack-Mitaka 高可用之 Mariadb-Galera集群 ...

  9. 移植WordPress到Ubuntu16.04

    移植WordPress到Ubuntu16.04 新建 模板 小书匠 移植WordPress到Ubuntu16.04 搭建好LAMP环境后,可以按照以下方法,将本地站点移植到服务器上. 以WordPre ...

  10. docker从零开始(四)集群初体验,docker-machine swarm

    介绍 在第三节中,选择了第二节中编写的应用程序,并通过将其转换为服务来定义它应如何在生产中运行,并生成五个应用实例 在本节中,将此应用程序部署到群集上,在多台计算机上运行它.多容器,多机应用程序通过连 ...