【动态规划】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

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;
}

转载于:https://www.cnblogs.com/autsky-jadek/p/6321740.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
支持代理协议:   HTTP, HTTPS, FTP, Telnet, NNTP, SMTP, POP, IMAP, LPR, LDAP, ICP, DNS, SSL, Socks   GateProxy.exe 是个能独立运行的软件,实用于Windows系统所有操作系统.支持WIN98(98上可能有少数性能限制,我没有仔细测试),WINNT,WIN2000,WINXP,WIN2003,VISTA系统,可能包括微软以后发布的操作系统,其原因就是直接走底层调用,不使用微软基本库 比较适合做入侵的朋友使用,这套代码也可以作为硬件防火墙做代理网关使用,当然要想做也还要手工制作的    文件列表: GateProxy.exe 软件制作说明: 本软件是完全粘贴EXE生成,用HEX进制编辑生成,纯手工制作,软件不支持任何形式的逆向工程和软件反编译 本程序是纯PE格式的文件,软件制作时horse_b用VC++实现了几个基本代理的EXE,基于这几个EXE,采用HEX编 辑生成最后的可执行代码GateProxy.exe 软件中绝对不含任何形式的后门和trojan程序,如果您发现任何木马迹象,请发邮件和我联系 软件使用说明: 请大家自己测试,软件支持命令行输入,也可以安装成服务,如果安装成服务,服务器端口可以走通本软件的所有代理协议 ParisProxy 项目说明 Paris 是欧洲古代神话传说中的特洛衣王子,我是为了怀念几年前研究木马的那段战斗式的生活起的名字,现在就把这个代理服务器叫ParisProxy ParisProxy 命令行参数 命令行参数是:gateproxy.exe -P8989 启动服务,通用代理端口是8989,8989端口可以走通Parisproxy的所有协议,如果不加-P8989就直接走单一协议 如果有人和我讨论用HEX和二进制开发软件,可以来信和我讨论: 我的专门接受此类问题的EMAIL: winddk64@gmail.com 或者 winddk64@163.com 请访问网站:www.horseb.org www.horseb.net  

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值