UVALive 5962 Strongly Connected Chemicals --最大独立集
题意:给n个阳离子和m个阴离子,并给出相互的吸引关系,求一个最大的点集,使其中的每个阴阳离子相互吸引。
解法:枚举每条边,使该条边存在,然后建立反图,求一个最大匹配,此时的点数减去最大匹配与ans求一个最大值即可。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
using namespace std;
#define N 207 int G[N][N],G2[N][N];
int match[N];
int vis[N];
char ss[N][N];
int n,m; int Search_Path(int s)
{
for(int v=;v<m;v++)
{
if(G[s][v] == )
continue;
if(!vis[v])
{
vis[v] = ;
if(match[v] == - || Search_Path(match[v]))
{
match[v] = s;
return ;
}
}
}
return ;
} int Max_match()
{
memset(match,-,sizeof(match));
int cnt = ;
for(int i=;i<n;i++)
{
memset(vis,,sizeof(vis));
if(Search_Path(i))
cnt++;
}
return cnt;
} int main()
{
int t,cs = ,i,j,k,h;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
for(i=;i<n;i++)
{
scanf("%s",ss[i]);
for(j=;j<m;j++)
G[i][j] = ss[i][j] - '';
}
int ans = ;
for(i=;i<n;i++) //枚举边
{
for(j=;j<m;j++)
{
if(G[i][j])
{
int cntn = ;
int cntm = ;
for(k=;k<n;k++)
if(G[k][j])
cntn++;
for(h=;h<m;h++)
if(G[i][h])
cntm++;
for(k=;k<n;k++)
{
for(h=;h<m;h++)
{
if(G[k][j]&&G[i][h])
G2[k][h] = -G[k][h];
else
G2[k][h] = ;
}
}
ans = max(ans,cntn+cntm-Max_match());
}
}
}
printf("Case %d: %d\n",cs++,ans);
}
return ;
}
UVALive 5962 Strongly Connected Chemicals --最大独立集的更多相关文章
- Light OJ 1373 Strongly Connected Chemicals 二分匹配最大独立集
m种阳离子 n种阴离子 然后一个m*n的矩阵 第i行第j列为1代表第i种阴离子和第j种阴离子相互吸引 0表示排斥 求在阳离子和阴离子都至少有一种的情况下 最多存在多少种离子能够共存 阴阳离子都至少须要 ...
- PTA Strongly Connected Components
Write a program to find the strongly connected components in a digraph. Format of functions: void St ...
- algorithm@ Strongly Connected Component
Strongly Connected Components A directed graph is strongly connected if there is a path between all ...
- cf475B Strongly Connected City
B. Strongly Connected City time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- Strongly connected(hdu4635(强连通分量))
/* http://acm.hdu.edu.cn/showproblem.php?pid=4635 Strongly connected Time Limit: 2000/1000 MS (Java/ ...
- 【CF913F】Strongly Connected Tournament 概率神题
[CF913F]Strongly Connected Tournament 题意:有n个人进行如下锦标赛: 1.所有人都和所有其他的人进行一场比赛,其中标号为i的人打赢标号为j的人(i<j)的概 ...
- HDU 4635 Strongly connected (Tarjan+一点数学分析)
Strongly connected Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) ...
- 【CodeForces】913 F. Strongly Connected Tournament 概率和期望DP
[题目]F. Strongly Connected Tournament [题意]给定n个点(游戏者),每轮游戏进行下列操作: 1.每对游戏者i和j(i<j)进行一场游戏,有p的概率i赢j(反之 ...
- HDU4625:Strongly connected(思维+强连通分量)
Strongly connected Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
随机推荐
- 使用正则表达式获取Sql查询语句各项(表名、字段、条件、排序)
string text = "select * from [admin] where aa=1 and cc='b' order by aa desc "; Regex reg = ...
- iOS 线程相关-----绝对de干货
平时用线程总是知其然,而不知所以然,现在针对涉及到的有关线程的知识体系做了一个系统的整理,由于GCD平时用的也比较多,所以用了大量的空间来讲述这一块,其他的涉及的不是很多,也做了说明,真真切切的是一个 ...
- IOS缓存机制详解
资料均来自互联网,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任. 人魔七七:http://www.cnblogs.com/qiqibo/ 为什么要有缓存 应用需要 ...
- mustache模板渲染的基本原理
mustache.js是一个模板引擎,为开发节省了大量的“人力”,对于初学者,我是从这篇 和这篇 博客接触的,算是对mustache有了初步认识,不得不承认自己还是菜鸟阶段还有太多东西要学,慢慢熟悉. ...
- js中的浅拷贝和深拷贝
说说最近所学:浅拷贝和深拷贝也叫做浅克隆和深克隆,深浅主要针对的是对象的"深度",常见的对象都是"浅"的,也就是对象里的属性就是单个的属性,而"深&q ...
- ASP.NET MVC another entity of the same type already has the same primary key value
ASP.NET MVC项目 Repository层中,Update.Delete总是失败 another entity of the same type already has the same pr ...
- javascript作用域链学习笔记
作用域链 "JavaScript中的函数运行在它们被定义的作用域里,而不是它们被执行的作用域里." --权威指南 在JavaScript中,一切皆对象,包括函数.函数对象和其它对象 ...
- 微信支付redirect_uri参数错误
在做微信支付的时候,点击提交,出现“redirect_uri参数错误”.经过查找,需要在后台正确设置授权域名.大致步骤如下:1.首先登录微信公众号管理后台2.点击开发者中心3.找到 网页账号—> ...
- 3.0之后在LinearLayout里增加分割线
android:divider="@drawable/shape"<!--分割线图片--> android:showDividers="middle|begi ...
- C编程常见问题总结
本文是C编程中一些常见错误的总结,有些是显而易见的,有些则是不容易发现 本文地址:http://www.cnblogs.com/archimedes/p/get-screwed-c.html,转载请注 ...