Gym-100923A-Por Costel and Azerah(DP)
链接:
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)的更多相关文章
- 【动态规划】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 ...
- 【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他们就就可以 ...
随机推荐
- k8s中使用harbor
参考地址:https://www.cnblogs.com/wayneiscoming/p/7716238.html .在harbor的ui界面上注册一个账号 姓名:zihao 全名:zhuzihao ...
- 基于Opencv的自适应中值滤波函数selfAdaptiveMedianBlur()
7.3.3 自适应滤波器 自适应中值滤波器 对于7.3.2节所讨论的中值滤波器,只要脉冲噪声的空间密度不大,性能还是可以的(根据经验需Pa和Pb小于0.2).本节将证明,自适应中值滤波器可以处理更大概 ...
- 【MM系列】SAP S/4 HANA 1511的BP角色创建及供应商数据的创建方法
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP S/4 HANA 1511的 ...
- 【计算机视觉】阶编码本模型(Multi phase codebook model)
转自:http://www.cnblogs.com/xrwang/archive/2012/04/24/MPCBBGM.html 多阶编码本模型(Multi phase codebook model) ...
- ajax的post请求crsftoken提交
- 使用自定义View
1 关于自定义的View的构造函数 java中对构造函数只是调用,不继承.因为整个UI是android系统提供的框架,因此构造函数需要写成它要求的格式,即和View的构造函数一样. 自定义的View中 ...
- Excel透视表基础之字段布局与重命名、更新、数字格式设置、空值与错误值、
字段布局与重命名 经典布局切换 字段布局 默认布局:文本类型在行区域.数字类型在值区域. 最好用鼠标拖拽. 字段重命名 可以在字段设置中更改. 透视表更新 延迟更新 手动刷新 自动刷新 刷新注意事项 ...
- 重装java后hadoop配置文件的修改
1.删除hdfs-site.xml中dfs.namenode.name.dir目录和dfs.datanode.data.dir目录 然后 hdfs namenode -format 不然将无法启动na ...
- 集成学习-组合策略与Stacking
集成学习是如何把多个分类器组合在一起的,不同的集成学习有不同的组合策略,本文做个总结. 平均法 对数值型输出,平均法是最常用的策略,解决回归问题. 简单平均法 [h(x)表示基学习器的输出] 加权平均 ...
- vs2012编译CZMQ-2.2.0
1.下载源代码包 到地址http://download.zeromq.org/czmq-2.2.0.zip下载源代码,解压缩到czmq-2.2.0文件夹下如图所看到的 watermark/2/text ...