二分匹配简单题,看懂题意,建图比较重要。

#include<stdio.h>
#include<string.h>
#define maxn 1100
int map[maxn][maxn];
int a[maxn],b[maxn],match[maxn],vis[maxn];
int n,m;
void makemap()
{
int i,j,k;
for(i=;i<=n;i++)
{
for(j=;j<=n;j++)
{
for(k=;k<=m;k++)
{
if(a[i]+a[j]==b[k])
{
map[i][j]=;
}
}
}
}
for(i=;i<=n;i++)
{
for(j=;j<=n;j++)
printf("%d ",map[i][j]);
printf("\n");
}
}
int dfs(int u)
{
int i,j;
for(i=;i<=n;i++)
{
if(!vis[i]&&map[u][i])
{
vis[i]=;
if(match[i]==-||dfs(match[i]))
{
match[i]=u;
return ;
}
}
}
return ;
}
int main()
{
int i,j,t;
scanf("%d",&t);
while(t--)
{
memset(map,,sizeof(map));
scanf("%d%d",&n,&m);
for(i=;i<=n;i++)
scanf("%d",&a[i]);
for(i=;i<=m;i++)
scanf("%d",&b[i]); makemap(); int ans=;
memset(match,-,sizeof(match)); for(i=;i<=n;i++)
{
memset(vis,,sizeof(vis));
if(dfs(i))
ans++;
}
printf("%d\n",ans/);
}
}

UVA5874 Social Holidaying 二分匹配的更多相关文章

  1. BNUOJ 12756 Social Holidaying(二分匹配)

    题目链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=12756 Social Holidaying Time Limit: 3000ms Memo ...

  2. POJ 1274 The Perfect Stall、HDU 2063 过山车(最大流做二分匹配)

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24081   Accepted: 106 ...

  3. [kuangbin带你飞]专题十 匹配问题 二分匹配部分

    刚回到家 开了二分匹配专题 手握xyl模板 奋力写写写 终于写完了一群模板题 A hdu1045 对这个图进行 行列的重写 给每个位置赋予新的行列 使不能相互打到的位置 拥有不同的行与列 然后左行右列 ...

  4. BZOJ 1189 二分匹配 || 最大流

    1189: [HNOI2007]紧急疏散evacuate Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1155  Solved: 420[Submi ...

  5. Kingdom of Obsession---hdu5943(二分匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5943 题意:给你两个数n, s 然后让你判断是否存在(s+1, s+2, s+3, ... , s+n ...

  6. poj 2060 Taxi Cab Scheme (二分匹配)

    Taxi Cab Scheme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5710   Accepted: 2393 D ...

  7. [ACM_图论] Sorting Slides(挑选幻灯片,二分匹配,中等)

    Description Professor Clumsey is going to give an important talk this afternoon. Unfortunately, he i ...

  8. [ACM_图论] The Perfect Stall 完美的牛栏(匈牙利算法、最大二分匹配)

    描述 农夫约翰上个星期刚刚建好了他的新牛棚,他使用了最新的挤奶技术.不幸的是,由于工程问题,每个牛栏都不一样.第一个星期,农夫约翰随便地让奶牛们进入牛栏,但是问题很快地显露出来:每头奶牛都只愿意在她们 ...

  9. nyoj 237 游戏高手的烦恼 二分匹配--最小点覆盖

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=237 二分匹配--最小点覆盖模板题 Tips:用邻接矩阵超时,用数组模拟邻接表WA,暂时只 ...

随机推荐

  1. [翻译]为你的服务器选择正确的.NET

    英文原文 By Daniel Roth ASP.NET 5 is based on the .NET Execution Environment (DNX), which supports runni ...

  2. UESTC 424 AreYouBusy --混合背包

    混合三种背包问题. 定义:dp[i][k]表示体积为k的时候,在前i堆里拿到的最大价值. 第一类,至少选一项,dp初值全赋为负无穷,这样才能保证不会出现都不选的情况.dp[i][k] = max(dp ...

  3. Centos7网络监控

    EPEL是企业版 Linux 附加软件包的简称,EPEL是一个由Fedora特别兴趣小组创建.维护并管理的,针对 红帽企业版 Linux(RHEL)及其衍生发行版(比如 CentOS.Scientif ...

  4. HDU 4941 Magical Forest --STL Map应用

    题意: 有n*m个格子(n,m <= 2*10^9),有k(k<=10^5)个格子中有值,现在有三种操作,第一种为交换两行,第二种为交换两列,交换时只有两行或两列都有格子有值或都没有格子有 ...

  5. SPOJ AMR10I Dividing Stones --DFS

    题意:给n个石头,分成一些部分(最多n部分,随便分),问分完后每部分的数量的乘积有多少种情况. 分析:可以看出,其实每个乘积都可以分解为素数的乘积,比如乘积为4,虽然可以分解为4*1,但是更可以分解为 ...

  6. 关于jQuery的一些实用代码

    (1)修改默认编码:(将默认的utf-8,修改为GB2312) $.ajaxSetup({ ajaxSettings:{contentType:"application/x-www-from ...

  7. Android 多线程----AsyncTask异步任务详解

    [声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/3 ...

  8. Windows远程桌面连接Ubuntu 14.04

    由于xrdp.gnome和unity之间的兼容性问题,在Ubuntu 14.04版本中仍然无法使用xrdp登陆gnome或unity的远程桌面,现象是登录后只有黑白点为背景,无图标也无法操作.与13. ...

  9. Css 常用属性

    1. overflow:hidden和zoom:1 verflow:hidden;的作用 1. 隐藏溢出 :2.消除浮动 <style type="text/css"> ...

  10. tkinter 改变按钮状态

    import tkinter as tk def btn1_change_btn1(event): '''方式一:通过事件控制自己''' if event.widget['state'] == 'no ...