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的更多相关文章

  1. 牛客网多校训练第二场D Kth Minimum Clique

    链接:https://ac.nowcoder.com/acm/contest/882/D来源:牛客网 Given a vertex-weighted graph with N vertices, fi ...

  2. 牛客网第二场Jfarm(随机化+二维前缀和)

    链接:https://www.nowcoder.com/acm/contest/140/J 来源:牛客网 White Rabbit has a rectangular farmland of n*m. ...

  3. Kth Minimum Clique

    Kth Minimum Clique 题目描述 Given a vertex-weighted graph with N vertices, find out the K-th minimum wei ...

  4. 牛客第三场多校 H Diff-prime Pairs

    链接:https://www.nowcoder.com/acm/contest/141/H来源:牛客网 Eddy has solved lots of problem involving calcul ...

  5. 牛客第五场多校 J plan 思维

    链接:https://www.nowcoder.com/acm/contest/143/J来源:牛客网 There are n students going to travel. And hotel ...

  6. 2019牛客第八场多校 E_Explorer 可撤销并查集(栈)+线段树

    目录 题意: 分析: @(2019牛客暑期多校训练营(第八场)E_Explorer) 题意: 链接 题目类似:CF366D,Gym101652T 本题给你\(n(100000)\)个点\(m(1000 ...

  7. 牛客网第一场E题 Removal

    链接:https://www.nowcoder.com/acm/contest/139/E 来源:牛客网 Bobo has a sequence of integers s1, s2, ..., sn ...

  8. 牛客网第一场 A Monotonic Matrix

    链接:https://www.nowcoder.com/acm/contest/139/A来源:牛客网 Count the number of n x m matrices A satisfying ...

  9. 牛客第三场多校 E Sort String

    链接:https://www.nowcoder.com/acm/contest/141/E来源:牛客网 Eddy likes to play with string which is a sequen ...

随机推荐

  1. 配置webpack中dev.env.js、prod.env.js,解决不同命令下项目启动和打包到指定的环境

    前后端分离的项目开发中,我们有开发环境.测试环境.预生产环境和生产环境. 1.开发环境下调试接口的时候,一般都会有好几个接口地址(开发服务器上的,本地的,接口开发人员的,七七八八的接口地址),要根据情 ...

  2. Java锁机制深入理解

    Java锁机制 背景知识 指令流水线 ​ CPU的基本工作是执行存储的指令序列,即程序.程序的执行过程实际上是不断地取出指令.分析指令.执行指令的过程. ​ 几乎所有的冯•诺伊曼型计算机的CPU,其工 ...

  3. VMware安装centos7与配置网络

    自己想搭建个虚机学习下k8s,使用VMware安装centos7,上不了网,折腾了很久才连上.发现网上很多教程都是错误的或者不明确的,这边写下自己的配置记录 首先安装centos7系统就不赘述了,这边 ...

  4. NetCore使用使用Scaffold-DbContext命令生成数据库表实体类

    一.为了模拟项目,本处创建了一个NetCore的Web项目.打算在Models文件夹下生成数据库表的实体类. 二.在程序包管理控制台,输入“Scaffold-DbContext "Serve ...

  5. 视频中“5s后可跳过广告” 设计目的

    来源:https://wen.woshipm.com/question/detail/0quoes.html 1.保证你在看.用户关掉广告这5秒内,他的眼睛会盯着屏幕,因为他知道5秒之后就能跳过广告. ...

  6. MongoDB geonear和文本命令驱动程序2.0

    文本查询,q作为查询字符串: coll.FindAsync<Foo>(Builders<Foo>.Filter.Text(q)); 文本查询需要一个文本索引.要从C#创建代码, ...

  7. Coursera 吴恩达 机器学习 学习笔记

    Week 1 机器学习笔记(一)基本概念与单变量线性回归 Week 2   机器学习笔记(二)多元线性回归 机器学习作业(一)线性回归——Matlab实现 机器学习作业(一)线性回归——Python( ...

  8. WebService 之 SoapHeader

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  9. linux - redis-trib.rb 命令详解

    参考网站 http://www.cnblogs.com/ivictor/p/9768010.html 简介 redis-trib.rb是官方提供的Redis Cluster的管理工具,无需额外下载,默 ...

  10. 心里没点B树,怎能吃透数据库索引底层原理?

    二叉树(Binary Search Trees) 二叉树是每个结点最多有两个子树的树结构.通常子树被称作“左子树”(Left Subtree)和“右子树”(Right Subtree).二叉树常被用于 ...