题目链接

传送门

题意

找第\(k\)小团。

思路

用\(bitset\)来标记每个结点与哪些结点直接有边,然后进行\(bfs\),在判断新加入的点与现在有的点是否都有边则直接用\(bitset\)与一下即可,记得去重。

代码

#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL; #define lson (rt<<1),L,mid
#define rson (rt<<1|1),mid + 1,R
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("/home/dillonh/CLionProjects/Dillonh/in.txt","r",stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0) const double eps = 1e-8;
const int mod = 1000000007;
const int maxn = 100 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL; int n, k;
bitset<101> vis[105];
int w[maxn], mp[maxn][maxn];
struct node {
LL val;
bitset<101> has;
bool operator < (const node& x) const {
return val > x.val;
}
}nw; priority_queue<node> q; int main() {
#ifndef ONLINE_JUDGE
FIN;
#endif
scanf("%d%d", &n, &k);
for(int i = 1; i <= n; ++i) {
scanf("%d", &w[i]);
nw.has.set(i), nw.val = w[i];
q.push(nw);
nw.has.reset(i);
}
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= n; ++j) {
scanf("%1d", &mp[i][j]);
if(mp[i][j]) vis[i].set(j);
}
}
LL ans = -1;
if(k == 1) {
printf("0\n");
return 0;
}
--k;
while(!q.empty()) {
nw = q.top(), q.pop();
if(--k == 0) {
ans = nw.val;
break;
}
int idx = 1;
for(int i = 1; i <= n; ++i) if(nw.has.test(i)) idx = i + 1;
for(int i = idx; i <= n; ++i) {
if(nw.has.test(i)) continue;
if((vis[i] & nw.has) != nw.has) continue;
nw.val += w[i];
nw.has.set(i);
q.push(nw);
nw.val -= w[i];
nw.has.reset(i);
}
}
printf("%lld\n", ans);
return 0;
}

Kth Minimum Clique(2019年牛客多校第二场D题+k小团+bitset)的更多相关文章

  1. MAZE(2019年牛客多校第二场E题+线段树+矩阵乘法)

    题目链接 传送门 题意 在一张\(n\times m\)的矩阵里面,你每次可以往左右和下三个方向移动(不能回到上一次所在的格子),\(1\)表示这个位置是墙,\(0\)为空地. 现在有\(q\)次操作 ...

  2. 2019年牛客多校第二场 F题Partition problem 爆搜

    题目链接 传送门 题意 总共有\(2n\)个人,任意两个人之间会有一个竞争值\(w_{ij}\),现在要你将其平分成两堆,使得\(\sum\limits_{i=1,i\in\mathbb{A}}^{n ...

  3. 2019年牛客多校第二场 H题Second Large Rectangle

    题目链接 传送门 题意 求在\(n\times m\)的\(01\)子矩阵中找出面积第二大的内部全是\(1\)的子矩阵的面积大小. 思路 处理出每个位置往左连续有多少个\(1\),然后对每一列跑单调栈 ...

  4. 2019年牛客多校第一场B题Integration 数学

    2019年牛客多校第一场B题 Integration 题意 给出一个公式,求值 思路 明显的化简公式题,公式是分母连乘形式,这个时候要想到拆分,那如何拆分母呢,自然是裂项,此时有很多项裂项,我们不妨从 ...

  5. Cutting Bamboos(2019年牛客多校第九场H题+二分+主席树)

    题目链接 传送门 题意 有\(n\)棵竹子,然后有\(q\)次操作,每次操作给你\(l,r,x,y\),表示对\([l,r]\)区间的竹子砍\(y\)次,每次砍伐的长度和相等(自己定砍伐的高度\(le ...

  6. 2019年牛客多校第一场 I题Points Division 线段树+DP

    题目链接 传送门 题意 给你\(n\)个点,每个点的坐标为\((x_i,y_i)\),有两个权值\(a_i,b_i\). 现在要你将它分成\(\mathbb{A},\mathbb{B}\)两部分,使得 ...

  7. 2019年牛客多校第一场 H题XOR 线性基

    题目链接 传送门 题意 求\(n\)个数中子集内所有数异或为\(0\)的子集大小之和. 思路 对于子集大小我们不好维护,因此我们可以转换思路变成求每个数的贡献. 首先我们将所有数的线性基的基底\(b\ ...

  8. 2019年牛客多校第一场 B题 Integration 数学

    题目链接 传送门 思路 首先我们对\(\int_{0}^{\infty}\frac{1}{\prod\limits_{i=1}^{n}(a_i^2+x^2)}dx\)进行裂项相消: \[ \begin ...

  9. 2019年牛客多校第一场 C题Euclidean Distance 暴力+数学

    题目链接 传送门 题意 给你\(n\)个数\(a_i\),要你在满足下面条件下使得\(\sum\limits_{i=1}^{n}(a_i-p_i)^2\)最小(题目给的\(m\)只是为了将\(a_i\ ...

随机推荐

  1. Visual Studio 2019(VS2019)正式版注册码秘钥

    Visual Studio 2019 EnterpriseBF8Y8-GN2QH-T84XB-QVY3B-RC4DF Visual Studio 2019 ProfessionalNYWVH-HT4X ...

  2. 解决Spring Cloud中Feign第一次请求失败的问题

    在Spring Cloud中,Feign和Ribbon在整合了Hystrix后,可能会出现首次调用失败的问题 com.netflix.hystrix.exception.HystrixTimeoutE ...

  3. debian系统配置

    使用腾讯docker源 sudo sed -i 's/deb.debian.org/mirrors.cloud.tencent.com/g' /etc/apt/sources.list sudo se ...

  4. Spring事务调用类自己方法失效解决办法和原因

    问题 正常情况下,我们都是在controller里调用service里的方法,这个方法如果需要加事务,就在方法上加上@Transactional,这样是没问题的,事务会生效. 可是如果像下面这样,绕以 ...

  5. SpringBoot+EventBus使用教程(一)

    一.简介 EventBus是一个基于发布订阅的事件总线,在Java和Android里都可以使用. 二.使用 1.引入pom <dependency> <groupId>org. ...

  6. Python学习教程(二)Python 安装和 Pycharm 环境配置

    一.Python 简介 Python 是一个高层次的结合了解释性.编译性.互动性和面向对象的脚本语言. Python 的设计具有很强的可读性,相比其他语言经常使用英文关键字,其他语言的一些标点符号,它 ...

  7. commitizen规范代码提交

    转载链接:https://www.jianshu.com/p/bd712e42f2e9 参考链接:https://segmentfault.com/a/1190000009048911 平时提交的变动 ...

  8. Django-orm高级

    ORM字段 orm常见字段 https://www.cnblogs.com/liuqingzheng/articles/9627915.html choice字段注释与数据渲染 性别 sex_choi ...

  9. Linux环境下如何计算CPU占用率【华为云技术分享】

    1.Linux 环境下查看 CPU 信息 1.1.查看 CPU 详细信息 通过 cat /proc/cpuinfo 命令,可以查看 CPU 相关的信息: [root@rh ~]$ cat /proc/ ...

  10. Mysql序列(八)—— group by排序问题

    在mysql中,group by默认会执行排序: By default, MySQL sorts GROUP BY col1, col2, ... queries as if you also inc ...