Atcoder Grand Contest 107 A Biscuits
A - Biscuits
Time limit : 2sec / Memory limit : 256MB
Score : 200 points
Problem Statement
There are N bags of biscuits. The i-th bag contains Ai biscuits.
Takaki will select some of these bags and eat all of the biscuits inside. Here, it is also possible to select all or none of the bags.
He would like to select bags so that the total number of biscuits inside is congruent to P modulo 2. How many such ways to select bags there are?
Constraints
- 1≤N≤50
- P=0 or 1
- 1≤Ai≤100
Input
Input is given from Standard Input in the following format:
N P
A1 A2 ... AN
Output
Print the number of ways to select bags so that the total number of biscuits inside is congruent to P modulo 2.
Sample Input 1
2 0
1 3
Sample Output 1
2
There are two ways to select bags so that the total number of biscuits inside is congruent to 0 modulo 2:
- Select neither bag. The total number of biscuits is 0.
- Select both bags. The total number of biscuits is 4.
Sample Input 2
1 1
50
Sample Output 2
0
Sample Input 3
3 0
1 1 1
Sample Output 3
4
Two bags are distinguished even if they contain the same number of biscuits.
Sample Input 4
45 1
17 55 85 55 74 20 90 67 40 70 39 89 91 50 16 24 14 43 24 66 25 9 89 71 41 16 53 13 61 15 85 72 62 67 42 26 36 66 4 87 59 91 4 25 26
Sample Output 4
17592186044416
排列组合
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
ll C(ll k,ll n)
{
ll pos=;
for(ll i=;i<k;i++)
{
pos*=(n-i);
pos/=(i+);
}
/*for(ll i=0;i<k;i++)
pos/=(i+1);*/
return pos;
}
int main()
{
ll n,m,ans=,pos=,x,cnt=;
cin>>n>>m;
for(ll i=;i<=n;i++)
{
cin>>x;
if(x%==) ans++;
else pos++;
}
if(m==)
{
cnt=;
ll nn=,mm=;
for(ll i=;i<=ans;i++)
nn+=C(i,ans);
for(ll i=;i<=pos;i+=)
mm+=C(i,pos);
cnt+=nn+mm+(nn*mm);
}
else
{
ll nn=,mm=;
for(ll i=;i<=ans;i++)
nn+=C(i,ans);
for(ll i=;i<=pos;i+=)
mm+=C(i,pos);
cnt+=(mm+(mm*nn));
}
cout<<cnt<<endl;
return ;
}
Atcoder Grand Contest 107 A Biscuits的更多相关文章
- AtCoder Grand Contest 012
AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...
- AtCoder Grand Contest 011
AtCoder Grand Contest 011 upd:这篇咕了好久,前面几题是三周以前写的... AtCoder Grand Contest 011 A - Airport Bus 翻译 有\( ...
- AtCoder Grand Contest 031 简要题解
AtCoder Grand Contest 031 Atcoder A - Colorful Subsequence description 求\(s\)中本质不同子序列的个数模\(10^9+7\). ...
- AtCoder Grand Contest 010
AtCoder Grand Contest 010 A - Addition 翻译 黑板上写了\(n\)个正整数,每次会擦去两个奇偶性相同的数,然后把他们的和写会到黑板上,问最终能否只剩下一个数. 题 ...
- AtCoder Grand Contest 009
AtCoder Grand Contest 009 A - Multiple Array 翻译 见洛谷 题解 从后往前考虑. #include<iostream> #include< ...
- AtCoder Grand Contest 008
AtCoder Grand Contest 008 A - Simple Calculator 翻译 有一个计算器,上面有一个显示按钮和两个其他的按钮.初始时,计算器上显示的数字是\(x\),现在想把 ...
- AtCoder Grand Contest 007
AtCoder Grand Contest 007 A - Shik and Stone 翻译 见洛谷 题解 傻逼玩意 #include<cstdio> int n,m,tot;char ...
- AtCoder Grand Contest 006
AtCoder Grand Contest 006 吐槽 这套题要改个名字,叫神仙结论题大赛 A - Prefix and Suffix 翻译 给定两个串,求满足前缀是\(S\),后缀是\(T\),并 ...
- AtCoder Grand Contest 005
AtCoder Grand Contest 005 A - STring 翻译 给定一个只包含\(ST\)的字符串,如果出现了连续的\(ST\),就把他删去,然后所有位置前移.问最后剩下的串长. 题解 ...
随机推荐
- python 中进制转换及format(),int()函数用法
python中数值型变量好像只能是十进制形式表示,其他类型变量只能以字符串形式存在,可以通过format函数将int类型变量转换成其他进制字符串,如下所示: v_code=15 # 2进制 x=for ...
- 洛谷 P2734 游戏 A Game
P2734 游戏 A Game 题目背景 有如下一个双人游戏:N(2 <= N <= 100)个正整数的序列放在一个游戏平台上,游戏由玩家1开始,两人轮流从序列的任意一端取一个数,取数后该 ...
- 利用hive源码解析sql查了哪些表哪些字段
在hiveserver2中使用了org.apache.hadoop.hive.ql.parse.BaseSemanticAnalyzer对抽象语法树(AST)进行语义分析,分析的过程可以得出hive查 ...
- iOS:UISplitViewController的创建
UISplitViewController是iPad特有的系统方法,主要效果就是呈现iPad的经典切割界面 代码创建实例: - (BOOL)application:(UIApplication *)a ...
- Python学习之三【对象和类型&&运算符】
[对象和类型] 学生的属性: 小明 对象 姓名:男 性别: 年龄: 身高: 体重: 籍贯: 五种基本对象类型 字符串 (string),简记为 str 使用 ' ' 或 " " 括 ...
- nginx模块开发
开发方法參考淘宝的教程 这个模块的功能是向client发送一个文件,类似于网页上的另存为功能 #include <ngx_config.h> #include <ngx_core.h ...
- 介绍Oracle自带的一些ASM维护工具 (kfod/kfed/amdu)
1.前言 ASM(Automatic Storage Management)是Oracle主推的一种面向Oracle的存储解决方式,它是一个管理卷组或者文件系统的软件.眼下已经被RAC环境广泛使用,可 ...
- 使用quick自己定义Button
使用quick时自己封装的类存放于特定的文件夹.便于以后使用 以下是作者经经常使用到的一个按钮 local MyButton = class("MyButton") functio ...
- HTML样式以及使用
HTML的样式包含: 1,标签{style ,link} 2.属性{rel="styleSheet"外部样式表,type="text/css",margin-l ...
- kindeditor 不能编辑 问题
/*显示上传窗体*/ function ShowUplodToDaily() { var _sdata = grid.getSelecteds(); if (_sdata) { /*创建编辑器*/ v ...