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 ...
随机推荐
- http get post
使用java代码模拟http请求 package ftp; import java.io.BufferedReader; import java.io.IOException; import java ...
- Visual Studio 2013下JSON可视化工具
Visual Studio 2013现在我们有个小工具可以实现JSON可视化,这样给我们调试JSON提供了便利. JSON这种数据格式已经比较流行,在WEB前端随处可见. 在你需要安装VS ...
- 浅谈RSA加密算法
一.什么是非对称加密 1.加密的密钥与加密的密钥不相同,这样的加密算法称之为非对称加密 2.密钥分为:公钥,私钥 公钥:可以对外给任何人的加密和解密的密码,是公开的 私钥:通过私钥可以生成公钥,但从 ...
- 深入了解Activity-生命周期
一 介绍 Activity是android中使用最为频繁的组件,在官方文档中是这样描述的:An activity is a single, focused thing that the user ca ...
- UITabBarController的创建等基本方法
#import "AppDelegate.h" @interface AppDelegate () <UITabBarControllerDelegate> @end ...
- 【转】从viewController讲到强制横屏,附IOS5强制横屏的有效办法
文字罗嗦,篇幅较长,只需营养可直接看红字部分. 一个viewController的初始化大概涉及到如下几个方法的调用: initWithNibName:bundle: viewDidLoad view ...
- IOS开发--仿制网易新闻
学习来源:袁峥老师的<快速集成App中顶部标题滚动条> 此次博文写的是按需求分析写代码,思路条理性杠杠的,可以提高的编码实现速度哦. 效果: 根据这个网易新闻的界面,需求分析: ...
- python 读写、创建 文件
python中对文件.文件夹(文件操作函数)的操作需要涉及到os模块和shutil模块. 得到当前工作目录,即当前Python脚本工作的目录路径: os.getcwd() 返回指定目录下的所有文件和目 ...
- 【转】PaxosLease算法--2PC看Paxos选主
原文请参考[[置顶] Paxos master选举--PaxosLease算法] 众所周知,为了避免Paxos算法的活锁问题,必须选举唯一的proposor.偏偏在Paxos原论文中,作者L. Lam ...
- 颠覆式前端UI开发框架:React
转自:http://www.infoq.com/cn/articles/subversion-front-end-ui-development-framework-react/ 基于HTML的前端界面 ...