AtCoder Grand Contest 017 A
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
题意:数组中选出一些数字,相加求和%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的更多相关文章
- AtCoder Grand Contest 017 F - Zigzag
题目传送门:https://agc017.contest.atcoder.jp/tasks/agc017_f 题目大意: 找出\(m\)个长度为\(n\)的二进制数,定义两个二进制数的大小关系如下:若 ...
- AtCoder Grand Contest 017 (VP)
contest link Official Editorial 比赛体验--之前做题的时候感觉 AtCoder 挺快的,现在打了VP之后发现还是会挂的--而且不是加载缓慢或者载不出来,直接给你一个无法 ...
- AtCoder Grand Contest 017 题解
A - Biscuits 题目: 给出 \(n\) 个物品,每个物品有一个权值. 问有多少种选取方式使得物品权值之和 \(\bmod\space 2\) 为 \(p\). \(n \leq 50\) ...
- AtCoder Grand Contest 017 迟到记
晚上去操场上浪. 回来以后看到好几个人开着 \(AtCoder\) 在打代码. ... ... 今天有 \(AtCoder\) 比赛 ? 管它呢, \(Kito\) 在切西瓜,先吃西瓜... 然后看 ...
- AtCoder Grand Contest 017
noi前橙名计划失败.全程搞C而gg…… A - Biscuits 题意:背包,求价值为奇/偶的方案数. #include<cstdio> #include<queue> #i ...
- 题解——ATCoder AtCoder Grand Contest 017 B - Moderate Differences(数学,构造)
题面 B - Moderate Differences Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Stat ...
- AtCoder Grand Contest 017 B
B - Moderate Differences Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Stateme ...
- 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(& ...
- AtCoder Grand Contest 012
AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...
随机推荐
- jquery easyui:EasyUI Treegrid 树形网格
用jquery easyui 的 Treegrid 树形网格 进行数据展示,不过官网的API 和 demo 让我愣了好久,摸索后整理出来供大家详细参看. jquery easyui 官网:http:/ ...
- C#高阶与初心:(二)P/Invoke平台调用
最近某个项目要采集交易终端的信息用于监管,主要厂商给出了API,C++版的...开启hard模式!!! C#调用C++的DLL基本就两种方法:加一个VC++项目包一层,或者使用P/Invoke(平台调 ...
- 设计模式学习笔记——Prototype原型模式
原型模型就是克隆. 还有深克隆.浅克隆,一切听上去都那么耳熟能详.
- java.lang.IllegalStateException: No instances available for localhost
在SpringCloud的项目中,我们使用了自动配置的OAuth2RestTemplate,RestTemplate,但是在使用这些restTemplate的时候,url必须是服务的名称,如果要调用真 ...
- Mybatis中的大于等于和小于等于
mybatis中可以直接使用>或<:但是不能直接使用>=或<=; 第一种写法(1): 原符号 < <= > >= & ' " 替换符号 ...
- Linux时间子系统之四:定时器的引擎:clock_event_device【转】
本文转载自:http://blog.csdn.net/droidphone/article/details/8017604 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[+] ...
- html5--6-56 阶段练习5-翻转效果
html5--6-56 阶段练习5-翻转效果 学习要点 运用所学过的知识完成一个简单的小练习,理解对动画的应用. @charset="UTF-8"; *{ ; ; } img{ w ...
- 关闭ext4文件系统的日志功能
最近在帮一个研究生弄一个虚拟化环境下的基于Innodb的日志文件的读写优化的实验,实验的具体详细内容就不说了,其中有一个步骤需要将MySQL的日志文件放置在一块单独的硬盘里面,这块硬盘要么是ext2, ...
- 区间DP 等腰三角形
题目描述:给定一个正N边形,可以通过连线将这个多边形分割成N-2个三角形,问这N-2个三角形中恰有k个等腰三角形的分割方法有多少?这个值可能很大,输出对9397取模的结果.数据范围:n,k <= ...
- javascript之递归得DOM文本
var tag=document.getElementsByTagName('body')[0]; function findChild(tag){ var child=tag.childNodes ...