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\),就把他删去,然后所有位置前移.问最后剩下的串长. 题解 ...
随机推荐
- Eclipse配置class文件输出目录
1, Eclipse选中项目名称,邮件选中“Build Path”,然后选择“Configure Build Path”--->选择“Source” Tab---->修改"Def ...
- 安装spark问题汇总
使用的版本是 spark-1.6.3-bin-without-hadoop 运行spark-shell报错 运行spark-sql报错找不到org.datanucleus.api.jdo.JDOPer ...
- 【Linux编程】socket编程
套接字是通信端点的抽象.文件描写叙述符用open函数创建,而套接字描写叙述符用socket函数创建.socket函数原型例如以下: int socket(int domain, int type, i ...
- 在KVM中执行windows 10虚机(by quqi99)
作者:张华 发表于:2015-12-22版权声明:能够随意转载.转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明 ( http://blog.csdn.net/quqi99 ) KVM ...
- Android笔记——Activity中的数据传递案例(用户注冊)
1.创建程序activity_main: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/andro ...
- Thinkphp 无法使用->order() 排序的两种解决的方法!
使用ThinkPHP,却发现无法使用->order($order)来排序. $order = " info.date2 desc "; 非常遗憾的是这样写结果order却变成 ...
- HDU4825:Xor Sum 解题报告(0/1 Trie树)
Problem Description Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包含了N个正整数. 随后 Prometheus 将向 Ze ...
- 以下三种下载方式有什么不同?如何用python模拟下载器下载?
问题始于一个链接https://i1.pixiv.net/img-zip-...这个链接在浏览器打开,会直接下载一个不完整的zip文件 但是,使用下载器下载却是完整文件 而当我尝试使用python下载 ...
- 查询SqlServer最近执行过的Sql
SELECT TOP 1000ST.text AS '执行的SQL语句' ,QS.execution_count AS '执行次数' ,QS.total_elapsed_time / 10000 AS ...
- sql索引碎片产生的原理 解决碎片的办法(sql碎片整理)
本文讲述了SQL SERVER中碎片产生的原理,内部碎片和外部碎片的概念.以及解决碎片的办法和填充因子.在数据库中,往往每一个对于某一方面性能增加的功能也会伴随着另一方面性能的减弱.系统的学习数据库知 ...