• nyoj 游戏高手的烦恼 (二分图最小点覆盖)


    还是想半天都没想明白。。 做得不多不熟,所以也联系不起来。

    二分图最小点覆盖= 二分图的匹配数  详细请看某周的hihocoder

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstdlib>
     4 #include<cstring>
     5 #include<string>
     6 #include<queue>
     7 #include<algorithm>
     8 #include<map>
     9 #include<iomanip>
    10 #include<climits>
    11 #include<string.h>
    12 #include<cmath>
    13 #include<stdlib.h>
    14 #include<vector>
    15 #include<set>
    16 #define INF 1e7
    17 #define MAXN 100010
    18 #define maxn 50
    19 #define maxm 1000
    20 #define Mod 1000007
    21 using namespace std;
    22 typedef long long LL;
    23 
    24 
    25 int T;
    26 int u, v;
    27 int n, m;
    28 int ans;
    29 vector<int> G[555];
    30 int vis[10010];
    31 int match[10010];
    32 
    33 bool path(int u)
    34 {
    35     for (int i = 0; i < G[u].size(); ++i) {
    36         int v = G[u][i];
    37         if (true == vis[v]) continue;
    38         vis[v] = true;
    39         if (match[v] == -1 || path(match[v])) {
    40             match[v] = u;
    41             return true;
    42         }
    43     }
    44     return false;
    45 }
    46 
    47 void hungarian()
    48 {
    49     ans = 0;
    50     memset(match,-1,sizeof(match));
    51     for (int i = 1; i <= n; ++i) {
    52         memset(vis,0,sizeof(vis));
    53         if (path(i)) ans++;
    54     }
    55 }
    56 
    57 void run()
    58 {
    59     scanf("%d%d",&n,&m);
    60     for (int i = 0; i <= n; ++i) {
    61         G[i].clear();
    62     }
    63     for (int i = 0; i < m; ++i) {
    64         scanf("%d%d",&u,&v);
    65         G[u].push_back(v);
    66     }
    67     hungarian();
    68     printf("%d
    ",ans);
    69     
    70 }
    71 int main()
    72 {
    73     scanf("%d", &T);
    74     while (T--)
    75         run();
    76     return 0;
    77 }
  • 相关阅读:
    WDM驱动加载方式理解
    应用程序与设备对象交换数据的三种方法
    IRP完成例程返回值理解
    关于IoCallDriver使用的疑惑
    Ring0打开其他设备对象三种方式整理
    DPC和ISR的理解
    Windows驱动开发技术详解HelloWDM例子win7下无法安装
    wdk中ramdisk代码解读
    内核编程键盘过滤几种方法思路整理
    IOAPIC重定位中断处理函数思路整理
  • 原文地址:https://www.cnblogs.com/usedrosee/p/4338195.html
Copyright © 2020-2023  润新知