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他们就就可以 ...
随机推荐
- Linux下获取安装包
https://blog.csdn.net/xiaofeng3011/article/details/82797614 # cat /etc/yum.conf [main]cachedir=/var/ ...
- java:Mybatis框架1(基本配置,log4j,Junit4(单元测试))
1.mybatis01: db.properties: driver=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/test userna ...
- Golang基础(6):go的net/http用法
http包提供了HTTP客户端和服务端的实现 一:http客户端的几种方法 1. func (c *Client) Get(url string) (resp *Response, err error ...
- Cocos2d-X多线程(3) cocos2dx中的线程安全
在使用多线程时,总会遇到线程安全的问题.cocos2dx 3.0系列中新加入了一个专门处理线程安全的函数performFunctionInCocosThread(),他是Scheduler类的一个成员 ...
- UML(统一建模语言)包含9种图
UML分为静态图.动态图 动态图:虚壮活血 () 静态图:租用配对累()
- java_第一年_JDBC(1)
JDBC(Java Data Base Connectivity),用于实现java语言编程与数据库连接的API. 数据库驱动:应用程序并不能直接使用数据库,而需要通过相应的数据库驱动程序后再操作数据 ...
- Ajax提交数据后,清空form表单
按钮不同,页面相同,还需要显示的数据不同,这里会由于页面的缓存问题,导致,每次点开这个页面显示的数据相同. 这不是我们想要的.这就需要清楚表单数据了. 如下: $('#myform')[0].rese ...
- Java编程思想读书笔记 第一章 对象导论
抽象过程 纯粹的面向对象程序设计方式: 万物皆为对象: 对象可以存储数据,还可以在其自身执行操作 程序是对象的集合: 通过发送消息告诉彼此要做的 每个对象都有自己的由其它对象构成的存储:可以在程序中构 ...
- Jquery复习(七)之尺寸
jQuery 尺寸 方法 jQuery 提供多个处理尺寸的重要方法: width() height() innerWidth() innerHeight() outerWidth() outerHei ...
- 定位class时空格注意
class属性中间的空格并不是空字符串,那是间隔符号,表示的是一个元素有多个class的属性名称,那定位的时候取其中的一个就行(并且要唯一) Selenium2+python自动化73-定位的坑:cl ...