牛客竞赛第二场D Kth Minimum Clique 贪心+bitmap
Kth Minimum Clique
题意
给出n(n<100)个点的邻接表,和n个点的权值,求第k大的团(完全子图)
分析
n很小,并且好像没有什么算法和这个有关系,所以可以往暴力枚举的方向想,那么问题就变成了如果枚举?很容易发现一个问题,如何才能补充不漏地枚举呢?肯定要遵循一定的顺序,集合类问题一般是从已选的最后一个点的顺序往后枚举,这样就可以不重不漏了,那怎么实现第k大的,使用优先队列即可。邻接表使用bitmap存储方便操作,可以说是一道Bitmap入门题?
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mkp make_pair
#define all(zzz) (zzz).being(),(zzz).end()
using namespace std;
typedef long long ll;
const int maxn=1e3+4;
char s[maxn][maxn];
ll a[maxn];
struct Node{
long long a;bitset<128> b;
Node(ll _a,bitset<128> _b){
a=_a;
b=_b;
}
bool operator<(const Node c)const{
return a>c.a;
}
};
bitset<128>judge[105];
int main(){
int n,k;
bitset<8>test;
// cout<<int(test[0])<<endl;
//cout<<z<<endl;
scanf("%d%d",&n,&k);
bitset<128>z;
for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
for(int i=1;i<=n;i++){
scanf("%s",s[i]+1);
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(i!=j)
if(s[i][j]=='1')
judge[i].set(j-1);
}
}
priority_queue<Node,vector<Node>>q;
for(int i=1;i<=n;i++){
z.reset();
q.push(Node(a[i],z.set(i-1)));
}
int cnt=1;
if(k==1){
cout<<0<<endl;
return 0;
}
while(!q.empty()){
z.reset();
auto tmp=q.top();
q.pop();
cnt++;
int id;
for(int i=127;i>=0;i--){
if((z.set(i)&tmp.b)[i]==1){
id=i+1;
break;
}
}
for(int i=id+1;i<=n;i++){
if((tmp.b&judge[i])==tmp.b){
auto tmp2=tmp;
q.push(Node(tmp.a+a[i],tmp2.b.set(i-1)));
}
}
if(cnt==k){
cout<<tmp.a<<endl;
return 0;
}
}
cout<<-1<<endl;
return 0;
}
牛客竞赛第二场D Kth Minimum Clique 贪心+bitmap的更多相关文章
- 牛客网多校训练第二场D Kth Minimum Clique
链接:https://ac.nowcoder.com/acm/contest/882/D来源:牛客网 Given a vertex-weighted graph with N vertices, fi ...
- 牛客网第二场Jfarm(随机化+二维前缀和)
链接:https://www.nowcoder.com/acm/contest/140/J 来源:牛客网 White Rabbit has a rectangular farmland of n*m. ...
- Kth Minimum Clique
Kth Minimum Clique 题目描述 Given a vertex-weighted graph with N vertices, find out the K-th minimum wei ...
- 牛客第三场多校 H Diff-prime Pairs
链接:https://www.nowcoder.com/acm/contest/141/H来源:牛客网 Eddy has solved lots of problem involving calcul ...
- 牛客第五场多校 J plan 思维
链接:https://www.nowcoder.com/acm/contest/143/J来源:牛客网 There are n students going to travel. And hotel ...
- 2019牛客第八场多校 E_Explorer 可撤销并查集(栈)+线段树
目录 题意: 分析: @(2019牛客暑期多校训练营(第八场)E_Explorer) 题意: 链接 题目类似:CF366D,Gym101652T 本题给你\(n(100000)\)个点\(m(1000 ...
- 牛客网第一场E题 Removal
链接:https://www.nowcoder.com/acm/contest/139/E 来源:牛客网 Bobo has a sequence of integers s1, s2, ..., sn ...
- 牛客网第一场 A Monotonic Matrix
链接:https://www.nowcoder.com/acm/contest/139/A来源:牛客网 Count the number of n x m matrices A satisfying ...
- 牛客第三场多校 E Sort String
链接:https://www.nowcoder.com/acm/contest/141/E来源:牛客网 Eddy likes to play with string which is a sequen ...
随机推荐
- Javascript的重要数据类型-对象
这次的分享,主要还是想跟大家聊聊Javascript语言中很重要的概念之一,对象.为什么说之一呢?因为Javascript其他重要概念还包括:作用域 作用域链 继承 闭包 函数 继承 数组 ..... ...
- 使用vim打开文件的16进制形式,编辑和全文替换
1.先用vim打开文件的二进制形式,如果不以二进制可能会产生转换错误. vim -b file-to-open.dat 2.用xxd把文件转换成十六进制格式 :%!xxd 现在就可以对待普通文本一样查 ...
- 【巨杉数据库Sequoiadb】巨杉⼯具系列之一 | ⼤对象存储⼯具sdblobtool
近期,巨杉数据库正式推出了完整的SequoiaDB 工具包,作为辅助工具,更好地帮助大家使用和运维管理分布式数据库.为此,巨杉技术社区还将持续推出工具系列文章,帮助大家了解巨杉数据库丰富的工具矩阵. ...
- os::commit_memory(0x0000000085330000, 2060255232, 0) failed; error='Cannot allocate memory' (errno=12)
centos 安装 elasticsearch的时候 因为 elasticsearch默认 需要 2G内存导致的镜像不能运行 解决方案 修改配置文件 find / -name jvm.options ...
- Winform form窗体已弹出框的形式出现并回传值
From2(弹出框)回传数据到From1 Form1(数据接收form): public string Sstr; private void button1_Click(object sender, ...
- 你所不知道的Hello World[C++实现]
要说OIer界内最简单的程序,那恐怕非Hello World莫属了, 那么这篇文章就介绍如何写Hello World(被打). 最简单的一种实现: #include <iostream> ...
- springboot整合websocket实现客户端与服务端通信
定义 WebSocket是通过单个TCP连接提供全双工(双向通信)通信信道的计算机通信协议.此WebSocket API可在用户的浏览器和服务器之间进行双向通信.用户可以向服务器发送消息并接收事件驱 ...
- MySQL登录和退出
登录必须保证服务是启动的(否则有权限有身份也进不来)进入仓库(数据库)前,有身份验证.需要有权限和密码 (用户名密码) 登录的方式一 通过MySQL自带的客户端 Command Line Client ...
- HDU1241 Oil Deposits(dfs+连通块问题)
背景描述 ztw同志负责探测地下石油储藏.ztw现在在一块矩形区域探测石油.他通过专业设备,来分析每个小块中是否蕴藏石油.如果这些蕴藏石油的小方格相邻(横向相邻,纵向相邻,还有对角相邻),那么它们被认 ...
- 高级特征工程I
Mean encodings 以下是Coursera上的How to Win a Data Science Competition: Learn from Top Kagglers课程笔记. 学习目标 ...