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\),就把他删去,然后所有位置前移.问最后剩下的串长. 题解 ...
随机推荐
- MAVEN flex
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- 【Henu ACM Round#24 A】k-String
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 如果是一个k-string的话. 考虑最后的串假设形式为sss..ss(k个s) 则s中出现的字母,整个串中最后出现的次数肯定为k的 ...
- HDU 3108 Ant Trip
Ant Trip Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- [AngularJS] ng-ture-value & ng-false-value
When you have a checkbox, not necessary that just 'ture' & 'false', you might have 'yes', 'no', ...
- nyoj--12--喷水装置(二)(区间覆盖问题+贪心)
喷水装置(二) 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 有一块草坪,横向长w,纵向长为h,在它的橫向中心线上不同位置处装有n(n<=10000)个点状的喷水 ...
- Python TurtleWorld configuration and simple test
TurtleWorld provides a set of functions for drawing lines by steering turtles around the screen. You ...
- Linux VNC Viewer客户端
1.realvnc-vnc-viewer 这个我感觉应该是做的做好用的VNC Viewer客户端了,毕竟是商业软件,但是VNC Viewer客户端是免费的.使用前 需要到官网下载对应发行版的软件包进行 ...
- c3p0-config.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE xml> <c3p0-confi ...
- ES6学习5 字符串的扩展
1.ES6 为字符串添加了遍历器接口,使得字符串可以被for...of循环遍历. for (let codePoint of 'foo') { console.log(codePoint) } // ...
- [洛谷P1119][codevs1817]灾后重建
题目大意:有n个村庄和一些连通两个村庄的双向道路.每个村庄在一个特定的时间修复.没有修复的村庄不能经过.现在有一系列询问,问两个村庄在t时刻的最短路(如果无法到达或两个村庄本身未修复,输出-1). 解 ...