Kth Minimum Clique_2019牛客暑期多校训练营(第二场)
题目连接:
https://ac.nowcoder.com/acm/contest/882/D
Description
Given a vertex-weighted graph with N vertices, find out the K-th minimum weighted clique.
A subset of vertices of an undirected graph is called clique if and only if every two distinct vertices in the subset are adjacent. The weight of a clique is the summation of the weight of vertices in it.
Input
The first line of input contains two space-separated integers N, K.
The second line of input contains N space-separated integers wi representing the weight of each vertex.
Following N lines each contains N characters eij. There's an edge between vertex i and vertex j if and only if eij = "1".
1 <= N <= 100
1 <= K <= 10^6
0 <= wi <= 10^9
Output
Output one line containing an integer representing the answer. If there's less than K cliques, output "-1".
Sample Input
2 3
1 2
01
10
Sample Output
2
Hint
题意
给出一个图的邻接矩阵,求该图的所有完全子图(点属于该图且任意两点有边)中权值第K小的价值,图权值为图中所有点的权值之和
题解:
用类似bfs的策略从0个点开始搜索,利用优先队列每次取出价值最小的子图,第K次出队的子图就是第K小的
代码
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <bitset>
using namespace std;
typedef long long ll;
const int mx = 105;
ll v[mx];
int n, k;
int mp[mx][mx];
bitset<mx> sum[mx];
struct Node {
bitset<mx> state;
ll value;
int last;
bool operator < (Node other) const {
return value > other.value;
}
};
ll solve() {
priority_queue <Node> Q;
Node st;
st.state.reset();
st.value = 0;
st.last = 0;
Q.push(st);
while (!Q.empty()) {
k--;
Node now = Q.top();
Node next = now;
Q.pop();
if (k == 0) return now.value;
for (int i = now.last+1; i <= n; i++) {
if ((now.state & sum[i]) == now.state) {
next = now;
next.state[i] = 1;
next.value += v[i];
next.last = i;
Q.push(next);
}
}
}
return -1;
}
char str[mx];
int main() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) scanf("%lld", &v[i]);
for (int i = 1; i <= n; i++) {
scanf("%s", str+1);
for (int j = 1; j <= n; j++) {
mp[i][j] = str[j]-'0';
if (mp[i][j]) sum[i][j] = 1;
}
}
printf("%lld\n", solve());
return 0;
}
Kth Minimum Clique_2019牛客暑期多校训练营(第二场)的更多相关文章
- 2019牛客暑期多校训练营(第二场) H-Second Large Rectangle(单调栈)
题意:给出由01组成的矩阵,求求全是1的次大子矩阵. 思路: 单调栈 全是1的最大子矩阵的变形,不能直接把所有的面积存起来然后排序取第二大的,因为次大子矩阵可能在最大子矩阵里面,比如: 1 0 0 1 ...
- 2020牛客暑期多校训练营 第二场 K Keyboard Free 积分 期望 数学
LINK:Keyboard Free 我要是会正经的做法 就有鬼了. 我的数学水平没那么高. 三个同心圆 三个动点 求围成三角形面积的期望. 不会告辞. 其实可以\(n^2\)枚举角度然后算出面积 近 ...
- 2020牛客暑期多校训练营 第二场 J Just Shuffle 置换 群论
LINK:Just Shuffle 比较怂群论 因为没怎么学过 置换也是刚理解. 这道题是 已知一个置换\(A\)求一个置换P 两个置换的关键为\(P^k=A\) 且k是一个大质数. 做法是李指导教我 ...
- 2020牛客暑期多校训练营 第二场 I Interval 最大流 最小割 平面图对偶图转最短路
LINK:Interval 赛时连题目都没看. 观察n的范围不大不小 而且建图明显 考虑跑最大流最小割. 图有点稠密dinic不太行. 一个常见的trick就是对偶图转最短路. 建图有点复杂 不过建完 ...
- 2020牛客暑期多校训练营 第二场 C Cover the Tree 构造 贪心
LINK:Cover the Tree 最受挫的是这道题,以为很简单 当时什么都想不清楚. 先胡了一个树的直径乱搞的贪心 一直过不去.后来意识到这类似于最经典长链剖分优化贪心的做法 然后那个是求最大值 ...
- 2020牛客暑期多校训练营 第二场 B Boundary 计算几何 圆 已知三点求圆心
LINK:Boundary 计算几何确实是弱项 因为好多东西都不太会求 没有到很精通的地步. 做法很多,先说官方题解 其实就是枚举一个点 P 然后可以发现 再枚举一个点 然后再判断有多少个点在圆上显然 ...
- 2020牛客暑期多校训练营 第二场 A All with Pairs 字符串hash KMP
LINK:All with Pairs 那天下午打这个东西的时候状态极差 推这个东西都推了1个多小时 (比赛是中午考试的我很困 没睡觉直接开肝果然不爽 一开始看错匹配的位置了 以为是\(1-l\)和\ ...
- 2019牛客暑期多校训练营(第九场) D Knapsack Cryptosystem
题目 题意: 给你n(最大36)个数,让你从这n个数里面找出来一些数,使这些数的和等于s(题目输入),用到的数输出1,没有用到的数输出0 例如:3 4 2 3 4 输出:0 0 1 题解: 认真想一 ...
- 2020牛客暑假多校训练营 第二场 H Happy Triangle set 线段树 分类讨论
LINK:Happy Triangle 这道题很容易. 容易想到 a+b<x a<x<b x<a<b 其中等于的情况在第一个和第三个之中判一下即可. 前面两个容易想到se ...
随机推荐
- Extjs的文件上传问题
最近做一个ExtJs4.0的文件上传.发现在没有添加 xtype:filefield, 时提交数据form的数据,修改form都能提交,而且返回正常.但是当加入xtype:filefield后,返 ...
- H3C模拟器单臂路由配置实例
单臂路由:用802.1Q和子接口实现VLAN间路由 单臂路由利用trunk链路允许多个VLAN的数据帧通过而实现 网络拓扑图: RTA配置: SW1配置: PC1/2配置如图: 但是值得注意的是,在配 ...
- Windows上的Linux容器
翻译自:https://docs.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/linux-contai ...
- java文字转语音播报功能的实现方法
java文字转语音播报功能的实现方法 一.pom.xml引入jar包依赖 <!-- https://mvnrepository.com/artifact/com.jacob/jacob 文字转语 ...
- html的一些基本属性介绍
一.html的属性类型: 1.常见标签属性: a.<h1>:align对其方式 例如:<h1 align="right"> hhhhh</ ...
- (二十六)c#Winform自定义控件-有确定取消的窗体(二)
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- java读取本机磁盘及遍历磁盘文件
1. 获取本机所有盘符信息 //1. 获取本机盘符 File[] roots = File.listRoots(); for (int i = 0; i < roots.length; i++) ...
- spring-boot-plus项目打包(七)
spring-boot-plus项目打包 项目打包 spring-boot-plus项目使用maven assembly插件进行打包 根据不同环境进行打包部署 包含启动.重启命令,配置文件提取到外部c ...
- Redis 5.0.5集群搭建
Redis 5.0.5集群搭建 一.概述 Redis3.0版本之后支持Cluster. 1.1.redis cluster的现状 目前redis支持的cluster特性: 1):节点自动发现 2):s ...
- 盘一盘 NIO (二)—— Channel解析
Channel是个啥? Channel,顾名思义,它就是一个通道.NIO中的所有IO都是从 Channel 开始的. Channel通道和流非常类似,主要有以下几点区别: 1.流是单向的,通道是双向的 ...