【动态规划】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
2
3
3 10 1
2
4 2
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;
}
【动态规划】Gym - 100923A - Por Costel and Azerah的更多相关文章
- 【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他们就就可以 ...
- Gym-100923A-Por Costel and Azerah(DP)
链接: https://vjudge.net/problem/Gym-100923A 题意: Por Costel the Pig has received a royal invitation to ...
随机推荐
- ViBe(Visual Background extractor)背景建模或前景检测
ViBe算法:ViBe - a powerful technique for background detection and subtraction in video sequences 算法官网: ...
- [codeforces/gym/100431/E]KMP关于border的理解
题目链接:http://codeforces.com/gym/100431/ 考虑到对于一个串β,能cover它的最短的α必然是它的border的某个前缀,或者是这个β本身. 所谓border,就是n ...
- webpack 引入 html-webpack-plugin 报错
配置webpack当中,出现一个问题: 引入html-webpack-plugin 插件报错. 这时需要本地(也就是当前项目下)安装一下webpack就可以解决问题了. 注意:现在是webpack4版 ...
- (转)tableview的索引设置
.感觉tableview的索引条将表视图往左边挤了一点?别担心,只是颜色问题.只要如此设置即可 //索引条背景的颜色(清空颜色就不会感觉索引条将tableview往左边挤) [_tableView s ...
- HDU2157 How many ways??---(邻接矩阵,图论,矩阵快速幂)
http://acm.hdu.edu.cn/showproblem.php?pid=2157 How many ways?? Time Limit: 2000/1000 MS (Java/Others ...
- codechef T1 What's int the name
NITIKA: 姓名本无意题目描述 Nitika 读了一本历史书,想要理清其中的人物关系.因此她要她的哥哥把书中出现的历史人 物全部列出来.哥哥把列好的人名给了 Nitika,但 Nitika 非常不 ...
- [Leetcode Week2]Sort List
Sort List题解 题目来源:https://leetcode.com/problems/sort-list/description/ Description Sort a linked list ...
- gcc 簡單操作
gcc -c test.c 產出 test.o object file gcc -c test.c -o XXX 產出 XXX object file gcc test.c -o aaa 產出 aaa ...
- You have not concluded your merge. (MERGE_HEAD exists)(转)
Git本地有修改如何强制更新 本地有修改和提交,如何强制用远程的库更新更新.我尝试过用git pull -f,总是提示 You have not concluded your merge. (MERG ...
- jQuery插件--zTree中点击节点实现页面跳转时弹出两个页面的问题
这是第一次使用zTree,所以在使用之前我要先写一个demo来学习一下.我们要注意的是,zTree是一个jQuery插件,所以我们在导入zTree的js文件之前要先导入jQuery的js文件. 我们先 ...