拆点二分图匹配

棋盘游戏

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 2146    Accepted Submission(s): 1250

Problem Description
小希和Gardon在玩一个游戏:对一个N*M的棋盘,在格子里放尽量多的一些国际象棋里面的“车”,而且使得他们不能互相攻击,这当然非常easy,可是Gardon限制了仅仅有某些格子才干够放。小希还是非常轻松的攻克了这个问题(见下图)注意不能放车的地方不影响车的互相攻击。

所以如今Gardon想让小希来解决一个更难的问题,在保证尽量多的“车”的前提下,棋盘里有些格子是能够避开的,也就是说,不在这些格子上放车,也能够保证尽量多的“车”被放下。可是某些格子若不放子。就无法保证放尽量多的“车”,这种格子被称做重要点。Gardon想让小希算出有多少个这种重要点,你能解决问题么?

 
Input
输入包括多组数据。 

第一行有三个数N、M、K(1<N,M<=100 1<K<=N*M),表示了棋盘的高、宽。以及能够放“车”的格子数目。接下来的K行描写叙述了全部格子的信息:每行两个数X和Y。表示了这个格子在棋盘中的位置。
 
Output
对输入的每组数据,依照例如以下格式输出: 

Board T have C important blanks for L chessmen.
 
Sample Input
3 3 4
1 2
1 3
2 1
2 2
3 3 4
1 2
1 3
2 1
3 2
 
Sample Output
Board 1 have 0 important blanks for 2 chessmen.
Board 2 have 3 important blanks for 3 chessmen.
 
Author
Gardon
 
Source
 

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; int mp[220][220],n,m,k;
int lf[220],rt[220];
int linker[220];
bool used[220]; bool dfs(int u)
{
for(int i=1;i<=m;i++)
{
if(mp[u][i])
if(used[i]==false)
{
used[i]=true;
if(linker[i]==-1||dfs(linker[i]))
{
linker[i]=u;
return true;
}
}
}
return false;
} int hungary()
{
int ret=0;
memset(linker,-1,sizeof(linker));
for(int i=1;i<=n;i++)
{
memset(used,false,sizeof(used));
if(dfs(i)) ret++;
}
return ret;
} int main()
{
int cas=1;
while(scanf("%d%d%d",&n,&m,&k)!=EOF)
{
memset(mp,false,sizeof(mp));
for(int i=0;i<k;i++)
{
scanf("%d%d",lf+i,rt+i);
mp[lf[i]][rt[i]]=true;
}
int bz=hungary(); int ans=0;
for(int i=0;i<k;i++)
{
mp[lf[i]][rt[i]]=false;
int tmp=hungary();
if(tmp<bz) ans++;
mp[lf[i]][rt[i]]=true;
}
printf("Board %d have %d important blanks for %d chessmen.\n",cas++,ans,bz);
}
return 0;
}

HDOJ 1281 棋盘游戏的更多相关文章

  1. hdu 1281 棋盘游戏

    http://acm.hdu.edu.cn/showproblem.php?pid=1281 棋盘游戏 Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  2. hdu 1281 棋盘游戏(二分匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1281 棋盘游戏 Time Limit: 2000/1000 MS (Java/Others)    M ...

  3. HDU 1281——棋盘游戏——————【最大匹配、枚举删点、邻接表方式】

     棋盘游戏 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status ...

  4. hdu 1281棋盘游戏(二分匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1281   Problem Description 小希和Gardon在玩一个游戏:对一个N*M的棋盘, ...

  5. HDU 1281 - 棋盘游戏 - [二分图最大匹配]

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1281 Time Limit: 2000/1000 MS (Java/Others) Mem ...

  6. HDU 1281 棋盘游戏 【二分图最大匹配】

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1281 题意概括: 有N*M大的棋盘,要在里面放尽量多的“车”,求最多能放的车的个数,和为了放最多的车有多 ...

  7. hdu 1281 棋盘游戏 (二分匹配)

    棋盘游戏 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  8. HDU——1281 棋盘游戏

    棋盘游戏 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  9. hdu 1281 棋盘游戏(二分图)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1281 每行每列作为节点,给可以放车的点将对应的行列连边,最多可放置的车即为建二分图后的最大匹配,跑一边 ...

随机推荐

  1. iOS NSNotificationCenter 最基本使用

    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:] , @"a ...

  2. iOS开发技巧 - 使用UIPickerView来选择值

    (Swift) import UIKit class ViewController: UIViewController, UIPickerViewDataSource { var picker: UI ...

  3. ZH奶酪:PHP抓取网页方法总结

    From:http://www.jb51.net/article/24343.htm 在做一些天气预报或者RSS订阅的程序时,往往需要抓取非本地文件,一般情况下都是利用php模拟浏览器的访问,通过ht ...

  4. Ubuntu 12.04.1 mysql从5.5升级到5.6

    Ubuntu 12.04.1 mysql从5.5升级到5.6 1 2 3 4 5 apt-cache search mysql-server sudo  apt-add-repository ppa: ...

  5. webkit webApp 开发技术要点总结[转]

    http://www.cnblogs.com/pifoo/archive/2011/05/28/webkit-webapp.html 如果你是一名前端er,又想在移动设备上开发出自己的应用,那怎么实现 ...

  6. lambda expressions are not supported at this language level

    IDEA下报错:lambda expressions are not supported at this language level 解决: 1. File -> Project Struct ...

  7. snabbdom vdom 框架

    1.snabbdom github地址:https://github.com/snabbdom/snabbdom 2.核心方法 var vnode = h('div#container.two.cla ...

  8. Maven依赖传递、依赖传递排除、依赖冲突

    转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6628429.html  一:Maven依赖传递 假如有Maven项目A,项目B依赖A,项目C依赖B.那么我们可 ...

  9. 找出以“b”开头的名字

    找出以“b”开头的名字:select * from pet where name like 'b%' “_”:匹配任何单个字符“%”:匹配任意数目字符(包括零字符)

  10. maven project创建填充项

    GroupID是项目组织唯一的标识符,实际对应JAVA的包的结构,是main目录里java的目录结构. ArtifactID就是项目的唯一的标识符,实际对应项目的名称,就是项目根目录的名称. 一般Gr ...