Description

Are you interested in pets? There is a very famous pets shop in the center of the ACM city. There are totally m pets in the shop, numbered from 1 to m. One day, there are n customers in the shop, which are numbered from 1 to n. In order to sell pets to as
more customers as possible, each customer is just allowed to buy at most one pet. Now, your task is to help the manager to sell as more pets as possible. Every customer would not buy the pets he/she is not interested in it, and every customer would like to
buy one pet that he/she is interested in if possible.

Input

There is a single integer T in the first line of the test data indicating that there are T(T≤100) test cases. In the first line of each test case, there are three numbers n, m(0≤n,m≤100) and e(0≤e≤n*m). Here, n and m represent the number of customers and
the number of pets respectively.

In the following e lines of each test case, there are two integers x(1≤x≤n), y(1≤y≤m) indicating that customer x is not interested in pet y, such that x would not buy y.

Output

For each test case, print a line containing the test case number (beginning with 1) and the maximum number of pets that can be sold out.

Sample Input

1
2 2 2
1 2
2 1

Sample Output

Case 1: 2

Source

2011年全国大学生程序设计邀请赛(福州)

题意:有n个人分别相应不喜欢某个宠物,问最多能卖出去几仅仅

思路:简单的二分图匹配。匈牙利算法模板

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
const int MAXN = 110; int g[MAXN][MAXN], vis[MAXN];
int lined[MAXN];
int n, m, e; int dfs(int u) {
for (int v = 1; v <= m; v++) {
if (g[u][v] && !vis[v]) {
vis[v] = 1;
if (lined[v] == -1 || dfs(lined[v])) {
lined[v] = u;
return 1;
}
}
}
return 0;
} int main() {
int t, cas = 1;;
scanf("%d", &t);
while (t--) {
memset(g, 1, sizeof(g));
memset(lined, -1, sizeof(lined));
scanf("%d%d%d", &n, &m, &e);
for (int i = 0; i < e; i++) {
int a, b;
scanf("%d%d", &a, &b);
g[a][b] = 0;
}
int ans = 0;
for (int i = 1; i <= n; i++) {
memset(vis, 0, sizeof(vis));
if (dfs(i))
ans++;
}
printf("Case %d: ", cas++);
printf("%d\n", ans);
}
return 0;
}

FZU - 2039 Pets (二分图匹配 2011年全国大学生程序设计邀请赛(福州))的更多相关文章

  1. fzu 2039 Pets (简单二分图 + (最大流 || 二分图))

    Are you interested in pets? There is a very famous pets shop in the center of the ACM city. There ar ...

  2. UVA 2039 Pets(网络流)

    Problem Description Are you interested in pets? There is a very famous pets shop in the center of th ...

  3. 博弈论(二分图匹配):NOI 2011 兔兔与蛋蛋游戏

    Description Input 输入的第一行包含两个正整数 n.m. 接下来 n行描述初始棋盘.其中第i 行包含 m个字符,每个字符都是大写英文字母"X".大写英文字母&quo ...

  4. HDOJ 5093 Battle ships 二分图匹配

    二分图匹配: 分别按行和列把图展开.hungary二分图匹配. ... 例子: 4 4 *ooo o### **#* ooo* 按行展开. .. . *ooo o#oo oo#o ooo# **#o ...

  5. hdu 3829 Cat VS Dog 二分图匹配 最大点独立集

    Cat VS Dog Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others) Prob ...

  6. HDOJ 5090 Game with Pearls 二分图匹配

    简单的二分图匹配: 每个位置可以边到这些数字甚至可以边 Game with Pearls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: ...

  7. UVA 12549 - 二分图匹配

    题意:给定一个Y行X列的网格,网格种有重要位置和障碍物.要求用最少的机器人看守所有重要的位置,每个机器人放在一个格子里,面朝上下左右四个方向之一发出激光直到射到障碍物为止,沿途都是看守范围.机器人不会 ...

  8. POJ 1274 裸二分图匹配

    题意:每头奶牛都只愿意在她们喜欢的那些牛栏中产奶,告诉每头奶牛愿意产奶的牛棚编号,求出最多能分配到的牛栏的数量. 分析:直接二分图匹配: #include<stdio.h> #includ ...

  9. BZOJ1433 ZJOI2009 假期的宿舍 二分图匹配

    1433: [ZJOI2009]假期的宿舍 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2375  Solved: 1005[Submit][Sta ...

随机推荐

  1. 学习Android Studio里的Gradle

    一直听说Gradle很强大,只是偶尔用Android Studio创建Demo的时候看到他一次,今天抽个时间完整记录一下. 1.gradle位置 Android Studio项目创建好之后,默认有3个 ...

  2. Li的前期工作Level_Set_Evolution_Without_Re-initialization_A_New_Variational_Formulation

    注意:因为页面显示原因.里头的公式没能做到完美显示,有须要的朋友请到我的资源中下载 无需进行又一次初始化的水平集演化:一个新的变分公式 Chunming Li , Chenyang Xu , Chan ...

  3. 使用开源库 TWMessageBarManager 展示系统级别的通知

    TWMessageBarManager 简单翻译 https://github.com/terryworona/TWMessageBarManager An iOS manager for prese ...

  4. RESTful学习文档

    视频讲解 http://www.tudou.com/programs/view/PaVOGeK_BOY/ 文档说明 http://www.csdn.net/article/2013-06-13/281 ...

  5. word转pdf图片问题

    经过整理总结出两类问题:1,pdf文件下载文档中某些图片显示红叉.     问题现象:pdf是通过word转换成,发现源文件doc和docx文档均出现上述问题:只是某些图片显示红叉.通过这两点确定和文 ...

  6. HDU1561:The more, The Better(树形DP+01背包)

    Problem Description ACboy很喜欢玩一种战略游戏,在一个地图上,有N座城堡,每座城堡都有一定的宝物,在每次游戏中ACboy允许攻克M个城堡并获得里面的宝物.但由于地理位置原因,有 ...

  7. 比起 JSON 更方便、更快速、更簡短的 Protobuf 格式

    Protocol Buffers 是由 Google 所推出的一格式(後台真硬),你可以把它想像成是 XML 或 JSON 格式,但是更小.更快,而且更簡潔.這能夠幫你節省網路與硬體資源,且你只需要定 ...

  8. 似然和对数似然Likelihood & LogLikelihood

    One of the most fundamental concepts of modern statistics is that of likelihood. In each of the disc ...

  9. (转)Unity3D新手引导开发手记

    转自:http://www.cnblogs.com/ybgame/p/3844315.html 最近开始接手新手引导的开发,记录下这块相关的心得 首先客户端是Unity,在接手前,前面的同学已经初步完 ...

  10. jQuery cssHook的经典例子

      /*--------------------------- example ------------------------------*/ $.cssHooks.foo = { get: fun ...