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他们就就可以 ...
随机推荐
- PyCharm给函数增加文档注释
选择函数名,左上角会出现一个小灯泡,点击小灯泡 选择第二项 选中调用的函数名 Ctrl + Q 显示注释 如何配置操作习惯 File > sitting > 搜索 'keymap' > ...
- os, sys, stat 模块使用
1.设置文件权限: 注意:设置权限之前要导入下面三个模块,否则报错, import os, sys, stat os.chmod("/home/a.txt", stat.S_IXG ...
- SheetJS js-xlsx 的使用, exceljs
js-xlsx 官方文档:https://sheetjs.gitbooks.io/docs/#sheetjs-js-xlsx npm xlsx地址:https://www.npmjs.com/pack ...
- [转帖]SUN/Oracle JDK还是OpenJDK?
你安装的是 https://www.cnblogs.com/shoufeng/p/9719995.html 目录 1 如何查看你安装的JDK版本 1.1 要用到的命令行工具 1.2 查看JDK的版本 ...
- 【转】mysql卸载(windows)
作者:cxy_Summer 来源:CSDN 原文:https://blog.csdn.net/cxy_Summer/article/details/70142322 版权声明:本文为博主原创文章,转载 ...
- Spring是如何使用责任链模式的?
关于责任链模式,其有两种形式,一种是通过外部调用的方式对链的各个节点调用进行控制,从而进行链的各个节点之间的切换. 另一种是链的每个节点自由控制是否继续往下传递链的进度,这种比较典型的使用方式就是Ne ...
- pandas中的数据结构-DataFrame
pandas中的数据结构-DataFrame DataFrame是什么? 表格型的数据结构 DataFrame 是一个表格型的数据类型,每列值类型可以不同 DataFrame 既有行索引.也有列索引 ...
- MongoDB和Redis的区别
1).内存管理机制 a.Redis的数据全部存储在内存当中,会定期写入到磁盘当中,当内存不够用时, 可以选择指定的LRU(最近最少使用算法)的算法删除数据: b.MongoDB数据存在内存,有Linu ...
- zookeeper 实战操作
一:监听服务端zookeeper节点数据改变 import java.io.IOException; import java.util.concurrent.CountDownLatch; impor ...
- jupyter notebook 使用多个python环境
conda install nb_conda_kernels 执行上面的命令,然后启动notebook就可以选择conda中的所有环境了