题意:给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 --最大独立集的更多相关文章

  1. Light OJ 1373 Strongly Connected Chemicals 二分匹配最大独立集

    m种阳离子 n种阴离子 然后一个m*n的矩阵 第i行第j列为1代表第i种阴离子和第j种阴离子相互吸引 0表示排斥 求在阳离子和阴离子都至少有一种的情况下 最多存在多少种离子能够共存 阴阳离子都至少须要 ...

  2. PTA Strongly Connected Components

    Write a program to find the strongly connected components in a digraph. Format of functions: void St ...

  3. algorithm@ Strongly Connected Component

    Strongly Connected Components A directed graph is strongly connected if there is a path between all ...

  4. cf475B Strongly Connected City

    B. Strongly Connected City time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  5. Strongly connected(hdu4635(强连通分量))

    /* http://acm.hdu.edu.cn/showproblem.php?pid=4635 Strongly connected Time Limit: 2000/1000 MS (Java/ ...

  6. 【CF913F】Strongly Connected Tournament 概率神题

    [CF913F]Strongly Connected Tournament 题意:有n个人进行如下锦标赛: 1.所有人都和所有其他的人进行一场比赛,其中标号为i的人打赢标号为j的人(i<j)的概 ...

  7. HDU 4635 Strongly connected (Tarjan+一点数学分析)

    Strongly connected Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) ...

  8. 【CodeForces】913 F. Strongly Connected Tournament 概率和期望DP

    [题目]F. Strongly Connected Tournament [题意]给定n个点(游戏者),每轮游戏进行下列操作: 1.每对游戏者i和j(i<j)进行一场游戏,有p的概率i赢j(反之 ...

  9. HDU4625:Strongly connected(思维+强连通分量)

    Strongly connected Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

随机推荐

  1. 被混淆的C#类库的反编译

    今天看公司以前的代码,用的是.NRT Reactor v4.4.7.5进行的混淆,直接使用.NET Reflector v8.5.0.179 是无法查看的,提示:Invalid number of d ...

  2. 一些C语言学习的国外资源

    下面的列表是在网上收集整理的C语言资料,包括PDF等多种格式 A Tutorial on Pointers and Arrays in C Beej's Guide to C Programming ...

  3. iOS自定义AlertView 与 ActionSheet 遮罩提示+弹出动画

    产品大人总是能够想到很多让人欣慰的点子,基本所有能提示的地方都要很多文案啊图片之类 由此封装了一个半透明黑色遮罩的alert类(假装有图.jpg) 代码略糙,just share (逃 下载链接

  4. OC数组排序

    NSArray *array = @[@"tailong", @"kaersasi", @"airuiliya", @"yingl ...

  5. IOS 自定义按钮(代码实现)+九宫格

    在一些下载应用里整个页面都是按钮,有好多好多,但是仔细观察不难发现他们很有规律.就像下面一样

  6. 【原】iOSCoreAnimation动画系列教程(二):CAKeyFrameAnimation【包会】

    在上一篇专题文章[原]iOSCoreAnimation动画系列教程(一):CABasicAnimation[包会]中我们学习了iOS核心动画CoreAnimation中CABasicAnimation ...

  7. iOS开发笔记15:地图坐标转换那些事、block引用循环/weak–strong dance、UICollectionviewLayout及瀑布流、图层混合

    1.地图坐标转换那些事 (1)投影坐标系与地理坐标系 地理坐标系使用三维球面来定义地球上的位置,单位即经纬度.但经纬度无法精确测量距离戒面积,也难以在平面地图戒计算机屏幕上显示数据.通过投影的方式可以 ...

  8. iOS之 PJSIP静态库编译(二)

    咱们书接上回: 上一篇编译好了PJsip这次我们来点实战 上次编译过后就不必做别的修改因为ios平台的库都支持了. 打开工程   找到 pjsip- apps/src/pjsua/ios/ipjsua ...

  9. 写过的一些Oracle相关的博客

    Oracle体系结构:http://blog.chinaunix.net/uid/25909722/cid-164523-list-1.html Oracle优化:http://blog.chinau ...

  10. cocos2d-x基础元素之显示对象

    bool HelloWorld::init() { if ( !Layer::init() ) { return false; } Size visibleSize = Director::getIn ...