链接:

https://vjudge.net/problem/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!

思路:

dp, 把子序列当成子串算了半天..

代码:

#include <iostream>
#include <memory.h>
#include <string>
#include <istream>
#include <sstream>
#include <vector>
#include <stack>
#include <algorithm>
#include <map>
#include <queue>
#include <math.h>
#include <cstdio>
#include <set>
#include <iterator>
#include <cstring>
using namespace std; typedef long long LL;
const int MAXN = 1e6+10;
const int MOD = 1e9+7; LL dp[MAXN][2], a[MAXN];
int n; int main()
{
freopen("azerah.in","r",stdin);
freopen("azerah.out","w",stdout);
int t;
cin >> t;
while (t--)
{
memset(dp, 0, sizeof(dp));
cin >> n;
for (int i = 1;i <= n;i++)
cin >> a[i];
if (a[1]%2)
dp[1][1] = 1;
else
dp[1][0] = 1;
for (int i = 2;i <= n;i++)
{
if (a[i]%2)
{
dp[i][0] = (dp[i-1][0]+dp[i-1][1])%MOD;
dp[i][1] = (dp[i-1][0]+dp[i-1][1]+1)%MOD;
}
else
{
dp[i][0] = (dp[i-1][0]*2LL+1)%MOD;
dp[i][1] = (dp[i-1][1]*2LL)%MOD;
}
}
cout << dp[n][0] << endl;
} return 0;
}

Gym-100923A-Por Costel and Azerah(DP)的更多相关文章

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

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

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

  3. 【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 ...

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

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

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

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

  6. 【数形结合】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 ...

  7. 【并查集】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 ...

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

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

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

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

随机推荐

  1. 老白关于rac性能调优的建议

    RAC应用设计方面需要在底层做很有设计.虽然ORACLE的售前人员总是说RAC的扩展性是透明的,只要把应用分到不同的节点,就可以平滑的扩展系统能力了.而事实上,RAC的CACHE FUSION机制决定 ...

  2. C++编译错误提示 [Error] name lookup of 'i' changed for ISO '

    在VC 6 中,i的作用域范围是函数作用域,在for循环外仍能使用变量i 即: for (int i = 0; i < n; ++i) {         //…… } cout<< ...

  3. tomcat7远程代码执行 ImageMagick 命令执行漏洞

    tomcat7远程代码执行 windows     / linux   ::$DATA ImageMagick 命令执行漏洞(CVE-2016–3714) base64编码

  4. Linux下面MariaDB 管理命令基础使用

    MariaDB 是 MySQL 的一个分,由于某些原因,使之取代了Mysql成为了 RHEL/CentOS 7 的默认数据库.针对数据库的操作我们经常做的操作就是增删查改,接下来就介绍下 MariaD ...

  5. Windows下备份mysql

    ---恢复内容开始---  Windows下备份mysql 第一步 编写脚本 ::设置时间变量 set "Ymd=%date:~0,4%%date:~5,2%%date:~8,2%%time ...

  6. hibernate字段映射枚举类型

    上一篇介绍了mybatis字段映射枚举类型,这一篇给大家介绍一下hibernate字段怎么去映射枚举类型的(这只是一种参考方式,映射方法还有很多种). 还是以上篇sku表为例,sku表里一个statu ...

  7. 洛谷 P2398 GCD SUM 题解

    题面 挺有意思的. 设f[i]表示gcd(i,j)=i的个数,g[i]表示k|gcd(i,j)的个数; g[i]=(n/i)*(n/i); g[i]=f[i]+f[2i]+f[3i]+...; 所以f ...

  8. C++中的自定义内存管理

    1,问题: 1,new 关键字创建出来的对象位于什么地方? 1,位于堆空间: 2,有没有可能位于其它地方? 1,有: 2,通过一些方式可以使动态创建的对象位于静态存储区: 3,这个存储区在程序结束后释 ...

  9. 使用Idea部署SSM项目后,访问路径为url:8080/项目名_war_exploded的解决方案

    在tomcat配置页的Deployment下,修改Application context为/,即可直接使用url:8080访问项目主页.

  10. ubuntu 安装mysql5.7

    一.Windows mysql5.6 解压版 安装 关于widnows平台上的安装教程,可参考百度经验: 链接:https://jingyan.baidu.com/article/f3ad7d0ffc ...