第k小团(Bitset+bfs)牛客第二场 -- Kth Minimum Clique

题意:
给你n个点的权值和连边的信息,问你第k小团的值是多少。
思路:
用bitset存信息,暴力跑一下就行了,因为满足树形结构,所以bfs+优先队列就ok了,其中记录下最后进入的点(以免重复跑)。
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>//sprintf islower isupper
#include <cstdlib>//malloc exit strcat itoa system("cls")
#include <iostream>//pair
#include <fstream>
#include <bitset>
//#include <map>
//#include<unordered_map>
#include <vector>
#include <stack>
#include <set>
#include <string.h>//strstr substr
#include <string>
#include <time.h>//srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
#include <cmath>
#include <deque>
#include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
#include <vector>//emplace_back
//#include <math.h>
//#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
#include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
#define mem(a,b) memset(a,b,sizeof(a))
#define fo(a,b,c) for(a=b;a<=c;++a)//register int i
#define fr(a,b,c) for(a=b;a>=c;--a)
#define pr printf
#define sc scanf
void swapp(int &a,int &b);
double fabss(double a);
int maxx(int a,int b);
int minn(int a,int b);
int Del_bit_1(int n);
int lowbit(int n);
int abss(int a);
//const long long INF=(1LL<<60);
const double E=2.718281828;
const double PI=acos(-1.0);
const int inf=(<<);
const double ESP=1e-;
const int mod=(int)1e9+;
const int N=(int)1e6+; int val[];
struct node
{
int End;
long long V;
bitset<> clique;//团
friend bool operator<(node a,node b)
{
return a.V>b.V;
}
};
bitset<> mp[];
priority_queue<node> q; int main()
{
int n,k,i,j;
sc("%d%d",&n,&k);
for(i=;i<=n;++i)
sc("%d",&val[i]);
for(i=;i<=n;++i)
for(j=;j<=n;++j)
{
int t;
sc("%1d",&t);
mp[i][j]=t;
}
bitset<> temp;
q.push({,,temp});
while(!q.empty())
{
node now=q.top();q.pop();
k--;
if(k==)
{
pr("%lld\n",now.V);
return ;
}
for(i=now.End+;i<=n;++i)
{
if((now.clique&mp[i])==now.clique)
{
node v=now;
v.clique[i]=;
v.End=i;
v.V+=val[i];
q.push(v);
}
}
}
pr("-1\n");
return ;
} /**************************************************************************************/ int maxx(int a,int b)
{
return a>b?a:b;
} void swapp(int &a,int &b)
{
a^=b^=a^=b;
} int lowbit(int n)
{
return n&(-n);
} int Del_bit_1(int n)
{
return n&(n-);
} int abss(int a)
{
return a>?a:-a;
} double fabss(double a)
{
return a>?a:-a;
} int minn(int a,int b)
{
return a<b?a:b;
}
第k小团(Bitset+bfs)牛客第二场 -- Kth Minimum Clique的更多相关文章
- 第k小团+bitset优化——牛客多校第2场D
模拟bfs,以空团为起点,用堆维护当前最小的团,然后进行加点更新 在加入新点时要注意判重,并且用bitset来加速判断和转移构造 #include<bits/stdc++.h> #incl ...
- Kth Minimum Clique(2019年牛客多校第二场D题+k小团+bitset)
目录 题目链接 题意 思路 代码 题目链接 传送门 题意 找第\(k\)小团. 思路 用\(bitset\)来标记每个结点与哪些结点直接有边,然后进行\(bfs\),在判断新加入的点与现在有的点是否都 ...
- 2019牛客多校第二场D-Kth Minimum Clique
Kth Minimum Clique 题目传送门 解题思路 我们可以从没有点开始,把点一个一个放进去,先把放入一个点的情况都存进按照权值排序的优先队列,每次在新出队的集合里增加一个新的点,为了避免重复 ...
- 牛客第二场A-run
链接:https://www.nowcoder.com/acm/contest/140/A 来源:牛客网 White Cloud is exercising in the playground. Wh ...
- 牛客第二场Dmoney
链接:https://www.nowcoder.com/acm/contest/140/D 来源:牛客网 题目描述 White Cloud has built n stores numbered to ...
- 牛客第二场 J farm
White Rabbit has a rectangular farmland of n*m. In each of the grid there is a kind of plant. The pl ...
- 牛客第二场-J-farm-二维树状数组
二维树状数组真的还挺神奇的,更新也很神奇,比如我要更新一个区域内的和,我们的更新操作是这样的 add(x1,y1,z); add(x2+1,y2+1,z); add(x1,y2+1,-z); add( ...
- 牛客第二场 C.message(计算几何+二分)
题目传送:https://www.nowcoder.com/acm/contest/140/C 题意:有n个云层,每个云层可以表示为y=ax+b.每个飞机的航线可以表示为时间x时,坐标为(x,cx+d ...
- 走环概率问题(至今有点迷)--牛客第二场( Eddy Walker)
思路: 概率结论题,好像属于线性递推,现在也不太懂(lll¬ω¬) #define IOS ios_base::sync_with_stdio(0); cin.tie(0); #include < ...
随机推荐
- ValueError: Cannot assign "\<QuerySet [<Area: China>]\>": "Area.parent" must be a "Area" instance.
在研究才Django自关联的过程中,在插入数据时爆出如下错误: ValueError: Cannot assign "<QuerySet [<Area: China>]&g ...
- linux端口释放
查看linux连接端口范围 cat /proc/sys/net/ipv4/ip_local_port_range 调低端口释放等待时间 echo 20 > /proc/sys/net/ipv4 ...
- JavaScript 高级系列之节流 [throttle] 与防抖 [debounce]
一.概念 这两个东西都是为了项目优化而出现的,官方是没有具体定义的,他们的出现主要是为了解决一些短时间内连续执行的事件带来性能上的不佳和内存的消耗巨大等问题:像这类事件一般像 scroll keyup ...
- 黑马lavarel教程---11、响应处理
黑马lavarel教程---11.响应处理 一.总结 一句话总结: 如果在昂扬状态,看学习视频和运动时间重合,会很舒服 1.jquery的$.post参数为什么不需要占位? 因为每个参数的类型不同,可 ...
- 哨兵模式java实例
/** * 测试Redis哨兵模式 * @author liu */ public class TestSentinels { @SuppressWarnings("resource&quo ...
- Centos 安装freesurfer fsl matlab 等软件---转自网络
freesurfer: freesurfer好安装,只需要下载官网源码包,如freesurfer5.3.tar.gz 下载至本地,解压: tar zxvf freesurfer5.3.tar.gz - ...
- Leaflet - 自定义弹出框(popup)
有两种方法,一种直接改 CSS,一种是通过继承拓展 popup. 方法一:改 CSS 下面是一个将原有样式清空的设置(可能清的不全,只是提供个思路) .l-popup { &--no-styl ...
- CSV Data Set Config参数说明
以下是CSV Data Set Config各个参数的简要说明: FileName:即同目录下csv文件的名称 File Encoding: 默认为ANSI Varible Names: 定义文本文件 ...
- Linux 源码安装nginx
编译参数详解:https://www.cnblogs.com/houyongchong/p/compileArgs.html 配置参数详解:https://www.cnblogs.com/houyon ...
- Windows下查找文件或文件夹被哪个进程占用
Linux下我们可以使用lsof +D /filepath/,查看到文件被那些进程占用. windows下也会经常遇到文件夹或文件无法删除或无法访问的问题,使用“资源监视器”可以找到占用的进程,可以尝 ...