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. Swaps and Inversions HDU - 6318 树状数组+离散化

    #include<iostream> #include<algorithm> #include<cstring> #include<cstdio> us ...

  2. How Many Tables HDU - 1213

    #include<iostream> using namespace std; ; int p[N]; int find(int x) { if(p[x]!=x) p[x]=find(p[ ...

  3. Wannafly Camp 2020 Day 2D 卡拉巴什的字符串 - 后缀自动机

    动态维护任意两个后缀的lcp集合的mex,支持在串末尾追加字符. Solution 考虑在 SAM 上求两个后缀的 LCP 的过程,无非就是找它们在 fail 树上的 LCA,那么 LCP 长度就是这 ...

  4. Java基于SSM在线学习系统设计与实现

                 Spring+SpringMVC+MyBatis+Bootstrap+Vue开发在线学习系统 本课题的主要内容是开发基于Java EE的在线学习平台,使用MVC经典开发模式. ...

  5. First Kernel-pwn

    Kernel pwn-极简题目的操作模式 完全参照M4x师傅的指导,用 hacklu的baby kernel迈了第一步 题目附带文件说明 一般题目会给出bzImage,.cpio, .sh文件 sh文 ...

  6. webpack 代理问题

    devServer host: '0.0.0.0' 或者是ip 形式的 ,proxy 中 的 target,host 需要为ip形式的地址, host: 'aa.a.com' 为字符形式的 ,prox ...

  7. cookie、session和application

    https://cloud.tencent.com/developer/article/1493869 前言: 一直想写一篇关于cookie和session的博客,由于种种原因,一直没有整理,这不,今 ...

  8. AcWing 1049. 大盗阿福

    //f[i,j]表示所有走了i步,且当前位于状态j的所有走法 j=1表示选第i个 j=0表示不选 //如果j=0 那么表示不选第i个 那么就可以从f[i-1,0]和f[i-1,1]转移过来 //如果j ...

  9. Android_侧滑菜单的实现

    1.创建侧滑菜单Fragment package com.example.didida_corder; import android.os.Bundle; import android.view.La ...

  10. 1307E - Cow and Treats 二分 枚举边界 容斥

    1307E - Cow and Treats 题意 有一排给定口味的草,并且给m头牛,每个牛都只吃一种口味的草,并且要吃给定数量个.现在可以安排牛从两边出发,方向向另一方向进发,每次路过符合他口味的草 ...