标签:put data- contains string 算法 mono ref poj field
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 14399 | Accepted: 7836 |
Description
Input
Output
Sample Input
3 4 1 1 1 3 2 2 3 2
Sample Output
2
Hint
好吧。。这类型的简单题就先刷到这把。。改深化投入了。。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int M = 1000 + 5;
int n, m;
int link[M];
bool MAP[M][M];
bool cover[M];
int ans;
void init()
{
int num;
int x;
int y;
memset(MAP, false, sizeof(MAP));
for(int i=1; i<=m; i++)
{
scanf("%d%d", &x, &y);
MAP[x][y]=true;
}
}
bool dfs(int x)
{
for(int y=1; y<=n; y++)
{
if(MAP[x][y] && !cover[y])
{
cover[y]=true;
if(link[y]==-1 || dfs(link[y]))
{
link[y]=x;
return true;
}
}
}
return false;
}
int main()
{
while(scanf("%d%d", &n, &m)!=EOF)
{
ans=0;
init();
memset(link, -1, sizeof(link));
for(int i=1; i<=n; i++)
{
memset(cover, false, sizeof(cover));
if( dfs(i) )
ans++;
}
printf("%d\n", ans);
}
return 0;
}
POJ 3014:Asteroids(二分匹配,匈牙利算法)
标签:put data- contains string 算法 mono ref poj field
原文地址:http://www.cnblogs.com/claireyuancy/p/6930656.html