链接:

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. caffe-----使用C++ 提取网络中间层特征数据

    最近实验,想要在c++下知道网络中间某一层的特征数据情况,查找了相关资料,记录一下. 其实在caffe框架里面是包含这种操作的,可以模仿tools/extract_features.cpp中的操作来得 ...

  2. Hibernate初了解

    Hibernate是一个开放源代码的对象关系映射框架, 它对JDBC进行了非常轻量级的对象封装,使得Java程序员可以随心所欲的使用对象编程思维来操纵数据库. Hibernate可以应用在任何使用JD ...

  3. 【转载】ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'

    转载出处 在网上下载了一个免安装包的MySQL,准备自己create database jhp_test,使用的时候出现报错,如下: ERROR (): Access denied for user ...

  4. excel常用公式--计算统计类

    Count/Countif/Countifs:条件计数. 注:count只能对数值进行统计 sum/sumif/sumifs:条件求和.   Average/Averageifs:  返回参数的平均值 ...

  5. [转帖]数据库默认驱动、URL、端口

    超详细的各种数据库默认驱动.URL.端口总结 http://database.51cto.com/art/201906/598043.htm 学习了解一下.  概述 今天主要对各种数据库默认端口和UR ...

  6. [转帖]基于VIM漏洞CVE-2019-12735的VIM宏后门病毒详解

    基于VIM漏洞CVE-2019-12735的VIM宏后门病毒详解 不明觉厉 只要是人做的东西 就会有bug 就会有安全问题 就看发现bug 或者是发现安全问题 有没有收益了 会用linux的都是比较熟 ...

  7. 简单而粗暴的方法画任意阶数Bezier曲线

    简单而粗暴的方法画任意阶数Bezier曲线 虽然说是任意阶数,但是嘞,算法原理是可以到任意阶数,计算机大概到100多阶就会溢出了 Bezier曲线介绍] [本文代码] 背景 在windows的Open ...

  8. nginx配置本地域名反向代理实现本地多域名80访问

    什么是反向代理? 代理:通过客户机的配置,实现让一台服务器代理客户机,客户的所有请求都交给代理服务器处理. 反向代理:用一台服务器,代理真实服务器,用户访问时,不再是访问真实服务器,而是代理服务器. ...

  9. HNUSTOJ-1512 奇怪的导弹(暴力)

    1512: 奇怪的导弹 时间限制: 3 Sec  内存限制: 32 MB提交: 31  解决: 13[提交][状态][讨论版] 题目描述 最近国际形势比较紧张,就拿中国来说,比如南海问题,钓鱼岛事件等 ...

  10. Linux 查看系统相关信息(系统发型版本及内核版本等)

    以下为 Linux 以下信息查看命令,记录以备用 # uname -a # 查看内核/操作系统/CPU信息 # /etc/issue # 查看操作系统版本 # cat /proc/cpuinfo # ...