【动态规划】Gym - 100923A - Por Costel and Azerah
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
2
3
3 10 1
2
4 2
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的更多相关文章
- 【Gym - 100923A】Por Costel and Azerah(思维水题)
Por Costel and Azerah Descriptions 给你n个数 问你,有多少个子序列 的和是偶数 Example Input 233 10 124 2 Output 33 题目链接 ...
- 【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 ...
- 【找规律】Gym - 100923L - Por Costel and the Semipalindromes
semipal.in / semipal.out Por Costel the pig, our programmer in-training, has recently returned from ...
- 【分块打表】Gym - 100923K - Por Costel and the Firecracker
semipal.in / semipal.out Por Costel the pig, our programmer in-training, has recently returned from ...
- 【数形结合】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 ...
- 【并查集】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 ...
- 【带权并查集】Gym - 100923H - Por Costel and the Match
裸题. 看之前的模版讲解吧,这里不再赘述了. #include<cstdio> #include<cstring> using namespace std; int fa[10 ...
- 【Gym - 100923I】Por Costel and the Pairs(思维题)
Por Costel and the Pairs Descriptions 有T组测试样例 有n个男的,n个女的,第i个人都有为当前一个大小为i的懒惰值,当一男一女懒惰值的乘积<=n他们就就可以 ...
- Gym-100923A-Por Costel and Azerah(DP)
链接: https://vjudge.net/problem/Gym-100923A 题意: Por Costel the Pig has received a royal invitation to ...
随机推荐
- Ubuntu使用vim编辑器时出现上下左右键变成ABCD
今天在配置安装php时,要打开配置文件做些修改,肯定是要使用到vim编辑器的,我按照之前的使用命令之类的,在用到上下左右键时居然出现了ABCD,这我就纳闷了,难道Ubuntu的vim编辑器和别的不一样 ...
- WCF分布式开发步步为赢(12):WCF事务机制(Transaction)和分布式事务编程
今天我们继续学习WCF分布式开发步步为赢系列的12节:WCF事务机制(Transaction)和分布式事务编程.众所周知,应用系统开发过程中,事务是一个重要的概念.它是保证数据与服务可靠性的重要机制. ...
- Java 中request.getInputStream()和BufferedReader 和 InputStreamReader 用法
关于request.getInputStream(): http://www.cnblogs.com/steve-cnblogs/articles/5420198.html 浏览器 采用了一种编码方式 ...
- zigbee ---- profile 和 cluster
在zigbee规范中,引入了profile, cluster的概念.具体说来,假设规范一个profile(可以理解成一套规定),这个profile用来规范智能家居领域的相关产品都要满足那些要求,那么h ...
- Spring 学习笔记(二)
一.Spring 中的bean配置 –配置形式:基于 XML 文件的方式:基于注解的方式 –Bean 的配置方式:通过全类名(反射).通过工厂方法(静态工厂方法 & 实例工厂方法).Fac ...
- NGINX : 如何屏蔽未被定义的虚拟主机的访问
参考: [ how to prevent undefined server names ] nginx 的默认虚拟主机 Nginx 支持基于域名和端口的虚拟主机(virtual host), 根据获取 ...
- 【洛谷 P1651】 塔 (差值DP)
题目链接 题意:\(n\)个木块放到两个塔里,每个木块可放可不放,使得两塔高度相同且高度最大,求最大高度. 这个差值\(DP\)的思维难度还是很大的,没想出来,我就打了一个\(dfs\)骗了好像\(2 ...
- bzoj 1001 平面图转对偶图 最短路求图最小割
原题传送门http://www.lydsy.com/JudgeOnline/problem.php?id=1001 整理了下之前A的题 平面图可以转化成对偶图,然后(NlogN)的可以求出图的最小割( ...
- redis有string,hash,list,sets.zsets几种数据类型
1.string数据类型 可包含任何数据,是二进制安全的,比如图片或者序列化的对象set key valueset name hkset age 20get name 得到"hk" ...
- swift网址
http://www.cocoachina.com/industry/20140613/8818.html Swift -- 中文版两大官方文档汇总发布于:2014-06-13 15:34阅读数:22 ...