Winner Winner

题目链接(点击)

题目描述

The FZU Code Carnival is a programming competetion hosted by the ACM-ICPC Training Center of Fuzhou University. The activity mainly includes the programming contest like ACM-ICPC and strive to provide participants with interesting code challenges in the future.

Before the competition begins, YellowStar wants to know which teams are likely to be winners. YellowStar counted the skills of each team, including data structure, dynamic programming, graph theory, etc. In order to simplify the forecasting model, YellowStar only lists M skills and the skills mastered by each team are represented by a 01 sequence of length M. 1 means that the team has mastered this skill, and 0 does not.

If a team is weaker than other teams, this team cannot be a winner. Otherwise, YellowStar thinks the team may win. Team A(a1, a2, ..., aM ) is weaker than team B(b1, b2, ..., bM ) if ∀i ∈ [1, M], ai ≤ bi and ∃i ∈ [1, M], ai < bi.

Since YellowStar is busy preparing for the FZU Code Carnival recently, he dosen’t have time to forecast which team will be the winner in the N teams. So he asks you to write a program to calculate the number of teams that might be winners.

输入

Input is given from Standard Input in the following format:

N M

s1 s2 . . . sN

The binary representation of si indicates the skills mastered by teami.

Constraints

1 ≤ N ≤ 2 × 106

1 ≤ M ≤ 20

0 ≤ si < 2M

输出

Print one line denotes the answer.

样例输入

3 3
2 5 6

样例输出

2

题意:

有n个队伍从1~n 有m种技能 十进制数转二进制表示每个队伍对技能的熟练程度 如果是1表示完全掌握 如果是0 没完全掌握 如果任意两支队伍 其中一个的每种技能都<=另外一支队伍 那么这个队伍不可能获胜 输出最终可能获胜的队伍数目

例如: 2 5 6

二进制表示为: 0 1 0

1 0 1

1 1 0

每一列代表一支队伍  分别为1、2、3

通过比较1 3 可以把3排除 其余的无论怎么比较都无法再排除 所以最终结果就是 2支队伍 分别是: 1、 2

思路:

看了题解说是dp 感觉也不是dp 就是先记录每个队伍 然后遍历排除其他的队伍 最后统计还剩多少不能排除的

例如: n=3 m=3    2 5 6

从最大值开始循环  6的二进制 1 1 0 可以看出来 6可以覆盖1 0 0 和 0 1 0 和 0 0 0 三个数分别为4 2 0 把它们的vis值变为-1 最后只统计vis值为正的 即是结果

AC代码:

#include<bits/stdc++.h>
using namespace std;
int vis[(1<<(20))+5];
int main()
{
int n,m,num;
scanf("%d%d",&n,&m);
memset(vis,0,sizeof(vis));
for(int i=0;i<n;i++){
scanf("%d",&num);
vis[num]++;
}
int ans=0;
for(int i=(1<<m)-1;i>=0;i--){
if(vis[i]!=0){
if(vis[i]>0){
ans+=vis[i]; ///vis[]为正ans直接加上
}
for(int j=m-1;j>=0;j--){
if(i&(1<<j)){
vis[i^(1<<j)]=-1; ///我感觉该是 vis[(1<<j)]赋值为 -1 但不知道为什么不可
} /// 以这样
}
}
}
printf("%d\n",ans);
return 0;
}

最新文章

  1. C语言标准库函数(网络上copy的)
  2. 深入浅出-iOS程序性能优化 (转载)
  3. debian8 配置使用 nfs
  4. R语言画图布局摆放(layout)
  5. Bootstrap系列 -- 27. 下拉菜单对齐方式
  6. 【Linux程序设计】之环境系统函数综合实验
  7. 利用Excel画柱状图,并且包含最大最小值
  8. .net 网站预编译命令
  9. ajax发送请求
  10. JAVA-2-DATA
  11. offset
  12. 10105 - Polynomial Coefficients
  13. HDU-1996-汉诺塔VI
  14. (转载)VB 查询Oracle中blob类型字段,并且把blob中的图片以流的方式显示在Image上
  15. 第二次项目冲刺(Beta阶段)5.24
  16. Docker笔记四:Elasticsearch实例部署
  17. 【API知识】RestTemplate的使用
  18. 资源中心的ES 服务的COM.IFLYTEK.ERSP.API.RESOURCEAPI 接口注册ZOOKEEPER失败,解决记录
  19. nexus、maven私服仓库(一)
  20. DotNetty项目基本了解和介绍

热门文章

  1. nodejs server启动写法
  2. (上)python3 selenium3 从框架实现学习selenium让你事半功倍
  3. python 串口 透传
  4. zookeeper安装部署步骤
  5. [C# WPF] 根据按钮动态跳转窗体
  6. MOS管的栅极和源极之间的电阻
  7. Android_存储之文件存储
  8. [SD心灵鸡汤]001.每月一则 - 2015.05
  9. 读Pyqt4教程,带你入门Pyqt4 _012
  10. pandas删除DataFrame中任意字段等于&#39;null&#39;字符串的行