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

Copy
2 0
1 3

Sample Output 1

Copy
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

Copy
1 1
50

Sample Output 2

Copy
0

Sample Input 3

Copy
3 0
1 1 1

Sample Output 3

Copy
4

Two bags are distinguished even if they contain the same number of biscuits.


Sample Input 4

Copy
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

Copy
17592186044416
题意:数组中选出一些数字,相加求和%2==p,有多少种选取方式,可以一个也不选
解法:
1 首先数组统统%2处理
2 p=0 说明可以选取0 或者偶数个1,那么C(0的总数,选取0的个数)*(1的总数,选取1的个数)
3 p=1 说明可以选取0加奇数个1,一样的公式
 #include<bits/stdc++.h>
using namespace std;
int num[];
int p,n;
long long C(int n,int m)
{
if(n<m) return ;
long long ans=;
for(int i=;i<m;i++) ans=ans*(long long)(n-i)/(long long)(i+);
return ans;
}
long long A(int n,int m)
{
if(n<m) return ;
long long ans=;
for(int i=;i<m;i++) ans*=(long long)(n-i);
return ans;
}
int main(){ int Numz=;
int Numo=;
cin>>n>>p;
for(int i=;i<=n;i++){
cin>>num[i];
num[i]%=;
if(num[i]==){
Numz++;
}else{
Numo++;
}
}
long long ans=;
if(p==){
for(int i=;i<=Numz;i++){
long long pos=C(Numz,i);
for(int j=;j<=Numo;j+=){
long long base=C(Numo,j);
ans+=(pos*base);
}
}
cout<<ans<<endl;
}else if(p==){
for(int i=;i<=Numz;i++){
long long pos=C(Numz,i);
for(int j=;j<=Numo;j+=){
long long base=C(Numo,j);
ans+=(pos*base);
}
}
cout<<ans<<endl;
}
return ;
}

AtCoder Grand Contest 017 A的更多相关文章

  1. AtCoder Grand Contest 017 F - Zigzag

    题目传送门:https://agc017.contest.atcoder.jp/tasks/agc017_f 题目大意: 找出\(m\)个长度为\(n\)的二进制数,定义两个二进制数的大小关系如下:若 ...

  2. AtCoder Grand Contest 017 (VP)

    contest link Official Editorial 比赛体验--之前做题的时候感觉 AtCoder 挺快的,现在打了VP之后发现还是会挂的--而且不是加载缓慢或者载不出来,直接给你一个无法 ...

  3. AtCoder Grand Contest 017 题解

    A - Biscuits 题目: 给出 \(n\) 个物品,每个物品有一个权值. 问有多少种选取方式使得物品权值之和 \(\bmod\space 2\) 为 \(p\). \(n \leq 50\) ...

  4. AtCoder Grand Contest 017 迟到记

    晚上去操场上浪. 回来以后看到好几个人开着 \(AtCoder\) 在打代码. ... ... 今天有 \(AtCoder\) 比赛 ? 管它呢, \(Kito\) 在切西瓜,先吃西瓜... 然后看 ...

  5. AtCoder Grand Contest 017

    noi前橙名计划失败.全程搞C而gg…… A - Biscuits 题意:背包,求价值为奇/偶的方案数. #include<cstdio> #include<queue> #i ...

  6. 题解——ATCoder AtCoder Grand Contest 017 B - Moderate Differences(数学,构造)

    题面 B - Moderate Differences Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Stat ...

  7. AtCoder Grand Contest 017 B

    B - Moderate Differences Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Stateme ...

  8. AtCoder Grand Contest 017题解

    传送门 \(A\) 直接转移就是了 typedef long long ll; const int N=55; ll f[N][2];int a[N],n,p; int main(){ scanf(& ...

  9. AtCoder Grand Contest 012

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

随机推荐

  1. CentOS笔记-其他杂记

    1.忘记密码时,可以用single模式来修改密码,为了安全,可以禁用single模式,参考网址如下 Centos服务器禁止单用户模式(single)来增强系统安全 2.远程登录:ssh root@xx ...

  2. CentOS笔记-系统概述

    Linux系统的启动过程并不是大家想象中的那么复杂,其过程可以分为5个阶段: 内核的引导. 当计算机打开电源后,首先是BIOS开机自检,按照BIOS中设置的启动设备(通常是硬盘)来启动. 操作系统接管 ...

  3. VC++ 对话框下使用工具栏

    关于这一技术网上也有很多的记录,下面仅记录我测试OK的代码.    在CXXDlg.h中添加如下成员变量: CToolBar m_ToolBar; CBitmap m_bmpTool; 在CXXDlg ...

  4. GNU Makeflie

    简介 Gnu Make主要用于构建和管理程序包.Makefile文件描述了整个工程的编译.连接等规则. 其中包括: 工程中的哪些源文件需要编译以及如何编译: 需要创建那些库文件以及如何创建这些库文件: ...

  5. HDU3294 Girls' research —— Manacher算法 输出解

    题目链接:https://vjudge.net/problem/HDU-3294 Girls' research Time Limit: 3000/1000 MS (Java/Others)    M ...

  6. YTU 2452: 麦克劳林用于函数求值

    2452: 麦克劳林用于函数求值 时间限制: 1 Sec  内存限制: 128 MB 提交: 18  解决: 12 题目描述 泰勒公式是一个用函数在某点的信息描述其附近取值的公式.如果函数足够光滑的话 ...

  7. ssm使用velocity模板语言

    1.在pom.xml里添加velocity模板语言支持的依赖 <!-- velocity模板语言支持包 --> <dependency> <groupId>org. ...

  8. hdu-3592 World Exhibition(差分约束)

    题目链接: World Exhibition Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 32768/32768 K (Java/ ...

  9. ES6之拷贝对象

    function copyObject(orig) { var copy = Object.create(Object.getPrototypeOf(orig)); //创建一个新的原型对象 copy ...

  10. Watir: 如何处理简单的网页弹出警告框?

    以下是一个很经典的把Watir与AutoIt连接在一起的实例.如果我们对AutoIT了解的更多,处理类似的问题会更加简单.以下实例会判断页面上是否有某“删除”链接,一旦有该链接,就点击,然后点击弹出的 ...