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的更多相关文章

  1. AtCoder Grand Contest 012

    AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...

  2. AtCoder Grand Contest 011

    AtCoder Grand Contest 011 upd:这篇咕了好久,前面几题是三周以前写的... AtCoder Grand Contest 011 A - Airport Bus 翻译 有\( ...

  3. AtCoder Grand Contest 031 简要题解

    AtCoder Grand Contest 031 Atcoder A - Colorful Subsequence description 求\(s\)中本质不同子序列的个数模\(10^9+7\). ...

  4. AtCoder Grand Contest 010

    AtCoder Grand Contest 010 A - Addition 翻译 黑板上写了\(n\)个正整数,每次会擦去两个奇偶性相同的数,然后把他们的和写会到黑板上,问最终能否只剩下一个数. 题 ...

  5. AtCoder Grand Contest 009

    AtCoder Grand Contest 009 A - Multiple Array 翻译 见洛谷 题解 从后往前考虑. #include<iostream> #include< ...

  6. AtCoder Grand Contest 008

    AtCoder Grand Contest 008 A - Simple Calculator 翻译 有一个计算器,上面有一个显示按钮和两个其他的按钮.初始时,计算器上显示的数字是\(x\),现在想把 ...

  7. AtCoder Grand Contest 007

    AtCoder Grand Contest 007 A - Shik and Stone 翻译 见洛谷 题解 傻逼玩意 #include<cstdio> int n,m,tot;char ...

  8. AtCoder Grand Contest 006

    AtCoder Grand Contest 006 吐槽 这套题要改个名字,叫神仙结论题大赛 A - Prefix and Suffix 翻译 给定两个串,求满足前缀是\(S\),后缀是\(T\),并 ...

  9. AtCoder Grand Contest 005

    AtCoder Grand Contest 005 A - STring 翻译 给定一个只包含\(ST\)的字符串,如果出现了连续的\(ST\),就把他删去,然后所有位置前移.问最后剩下的串长. 题解 ...

随机推荐

  1. [luogu]P4316 绿豆蛙的归宿(拓扑排序,期望)

    P4316 绿豆蛙的归宿 题目背景 随着新版百度空间的上线,Blog宠物绿豆蛙完成了它的使命,去寻找它新的归宿. 题目描述 给出一个有向无环图,起点为1终点为N,每条边都有一个长度,并且从起点出发能够 ...

  2. 国庆 day 7 上午

    思路:模拟,set记录一下. #include<set> #include<cstdio> #include<cstring> #include<iostre ...

  3. WPF-MVVM-Demo

    MVVM The model-view-viewmodel is a typically WPF pattern. It consists of a view that gets all the us ...

  4. Java - Thinking in Java 第2章 一切都是对象

    Java是"纯粹"的面向对象的语言. 操作的标示符是对象的一个引用, new是创建一个对象. 存储位置: 寄存器\堆栈(引用)\堆(new)\常量存储(程序代码内部)\非RAM存储 ...

  5. Making User-Managed Backups-17.4、Making User-Managed Backups of Online Tablespaces and Datafiles

    17.4.Making User-Managed Backups of Online Tablespaces and Datafiles 当数据库打开时,能够备份一个在线表空间全部和一个指定的数据文件 ...

  6. IT男送什么礼物给女朋友呢?

    每到各种节日,加班到吐血的IT男们,总是没什么时间准备礼物给女朋友,偶尔想起又不知道送什么的好,女朋友虽然心里不说,多少有些难过.现在推荐朋友的羊毛毡手工店,每一件都是亲手制作,特别是可以个性定制,女 ...

  7. 1570. [POJ3461]乌力波

    ★☆   输入文件:oulipo.in   输出文件:oulipo.out   简单对比时间限制:1 s   内存限制:256 MB [题目描述] 法国作家乔治·佩雷克(Georges Perec,1 ...

  8. js 字符串首字母转为大写 正则

    function replaceReg(str){ var reg = /\b(\w)|\s(\w)/g; str = str.toLowerCase(); return str.replace(re ...

  9. request.getxxxxxx()的使用方法

    request.getSchema() 可以返回当前页面使用的协议,http 或是 https; request.getServerName() 可以返回当前页面所在的服务器的名字; request. ...

  10. vue使用axios中 this 指向问题

    1.解决办法 在vue中使用axios做网络请求的时候,会遇到this不指向vue,而为undefined,可以使用箭头函数"=>"来解决.如下: methods: { lo ...