给你一个二分图 问你最大团为多大

解一:状压DP

解二:二分图最大匹配

二分图的最大团=补图的最大独立集

二分图最大独立集=二分图定点个数-最大匹配

//Hungary
#include<bits/stdc++.h>
using namespace std;
#define N 50
int useif[N]; //记录y中节点是否使用 0表示没有访问过,1为访问过
int link[N]; //记录当前与y节点相连的x的节点
int mat[N][N]; //记录连接x和y的边,如果i和j之间有边则为1,否则为0
int gn, gm; //二分图中x和y中点的数目
int can(int t) {
int i;
for (i = ; i <= gm; i++) {
if (useif[i] == && mat[t][i]) {
useif[i] = ;
if (link[i] == - || can(link[i])) {
link[i] = t;
return ;
}
}
}
return ;
}
int MaxMatch() {
int i, num;
num = ;
memset(link, 0xff, sizeof(link));
for (i = ; i <= gn; i++) {
memset(useif, , sizeof(useif));
if (can(i)) {
num++;
}
}
return num;
}
int main() {
int TCASE;
scanf("%d", &TCASE);
while (TCASE--) {
int n, k;
int u, v;
scanf("%d %d", &n, &k);
gn = gm = n;
memset(mat, , sizeof(mat));
for (int i = ; i <= k; i++) {
scanf("%d %d", &u, &v);
mat[u][v] = ;
}
for (int i = ; i <= n; i++) {
for (int j = ; j <= n; j++) {
mat[i][j] = mat[i][j] ^ ;
}
}
int ans = n * ;
ans -= MaxMatch();
printf("%d\n", ans);
}
}

Gym - 101915D Largest Group 最大团的更多相关文章

  1. POJ2985 The k-th Largest Group[树状数组求第k大值+并查集||treap+并查集]

    The k-th Largest Group Time Limit: 2000MS   Memory Limit: 131072K Total Submissions: 8807   Accepted ...

  2. POJ 2985 The k-th Largest Group(树状数组 并查集/查找第k大的数)

    传送门 The k-th Largest Group Time Limit: 2000MS   Memory Limit: 131072K Total Submissions: 8690   Acce ...

  3. poj 2985 The k-th Largest Group 树状数组求第K大

    The k-th Largest Group Time Limit: 2000MS   Memory Limit: 131072K Total Submissions: 8353   Accepted ...

  4. 【POJ2985】【Treap + 并查集】The k-th Largest Group

    Description Newman likes playing with cats. He possesses lots of cats in his home. Because the numbe ...

  5. POJ2985 The k-th Largest Group (并查集+treap)

    Newman likes playing with cats. He possesses lots of cats in his home. Because the number of cats is ...

  6. Gym 101775A - Chat Group - [简单数学题][2017 EC-Final Problem A]

    题目链接:http://codeforces.com/gym/101775/problem/A It is said that a dormitory with 6 persons has 7 cha ...

  7. Gym - 101775A Chat Group 组合数+逆元+快速幂

    It is said that a dormitory with 6 persons has 7 chat groups ^_^. But the number can be even larger: ...

  8. POJ2985 The k-th Largest Group treap

    POJ2985 比较简单的平衡树题目 树内不要添加容量为1的节点 否则会超时. #include<iostream> #include<cstdio> #include< ...

  9. 【LeetCode】1399. 统计最大组的数目 Count Largest Group

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 直接求 日期 题目地址:https://leetcod ...

随机推荐

  1. Linux 下 Mysql忘记密码重置

    1.修改配置文件 /etc/my.cnf 在[mysqld]下 加入skip-grant-tables 2.重启mysql 命令:service mysqld restart 3.等待几分钟后 就可以 ...

  2. delphi 双击dbgrid 调用另一窗体的例子

    unit Unit1; interface uses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Form ...

  3. 致远OA利用POC

    批量检测url 在脚本同目录下建立url.txt 放入待检测的URL 运行脚本 # Wednesday, 26 June 2019 # Author:nianhua # Blog:https://gi ...

  4. Misc题目

    @freebuff教程https://www.freebuf.com/column/196815.html @巅峰极客wp https://www.anquanke.com/post/id/18914 ...

  5. DQN算法原理详解

    一. 概述 强化学习算法可以分为三大类:value based, policy based 和 actor critic. 常见的是以DQN为代表的value based算法,这种算法中只有一个值函数 ...

  6. 设计模式:备忘录模式(Memento)

    个人比较喜欢玩单机游戏,什么仙剑.古剑.鬼泣.使命召唤.三国无双等等一系列的游戏我都玩过(现在期待凡人修仙传),对于这些游戏除了剧情好.场面大.爽快之外,还可以随时存档,等到下次想玩了又可以从刚开始的 ...

  7. ATM机小程序

    用规范化项目录的格式模拟一个ATM系统. 项目功能: 登录(可支持多个账户(非同时)登录) 注册 查看余额 存钱 转账(给其他用户转钱) 查看账户流水 退出 提供的思路:ATM直译就是取款机,但是咱们 ...

  8. ps -ef

    status, msg = commands.getstatusoutput("ps -ef | grep start.sh | grep -Fv grep | awk '{print $1 ...

  9. Python验证码登录(Tesseract安装配置)

    1.安装py库:pytesseract,PIL pip install pytesseract pip install PILLOW 如果安装时,出现权限不足: pip install --user ...

  10. Codeforces 1196E. Connected Component on a Chessboard

    传送门 注意到棋盘可以看成无限大的,那么只要考虑如何构造一个尽可能合法的情况 不妨假设需要的白色格子比黑色格子少 那么容易发现最好的情况之一就是白色排一排然后中间黑的先连起来,剩下黑色的再全部填白色周 ...