zoukankan      html  css  js  c++  java
  • HDOJ 1083 Hungarian实现

     1 #include<cstdio>
     2 #include<vector>
     3 
     4 using namespace std;
     5 
     6 #define N1 100
     7 #define N2 300
     8 
     9 int match[N2];
    10 vector<int> graph[N1];
    11 bool visit[N2];
    12 
    13 bool hungarian(int u){
    14     for (auto i = graph[u].begin(); i != graph[u].end(); i++)
    15         if (!visit[*i]){
    16             visit[*i] = 1;
    17             if (match[*i] == -1 || hungarian(match[*i])){
    18                 match[*i] = u;
    19                 return true;
    20             }
    21         }
    22     return false;
    23 }
    24 
    25 int main(){
    26     int m;
    27     scanf("%d", &m);
    28     for (int i = 0; i < m; i++){
    29         int p, n;
    30         bool flag = 0;
    31         scanf("%d %d", &p, &n);
    32         for (int j = 0; j < p; j++){
    33             int num;
    34             scanf("%d", &num);
    35             graph[j].clear();
    36             for (int l = 0; l < num; l++){
    37                 int student;
    38                 scanf("%d", &student);
    39                 graph[j].push_back(student - 1);
    40             }
    41         }
    42         for (int j = 0; j < n; j++)
    43             match[j] = -1;
    44         for (int j = 0; j < p; j++){
    45             for (int l = 0; l < n; l++)
    46                 visit[l] = 0;
    47             if (!hungarian(j)){
    48                 flag = 1;
    49                 break;
    50             }
    51         }
    52         if (flag)
    53             printf("NO
    ");
    54         else
    55             printf("YES
    ");
    56     }
    57     return 0;
    58 }
  • 相关阅读:
    junit spring
    DFU协议介绍
    USB枚举过程
    触摸板单点描述符
    Linux下使用codeblocks交叉编译ARM-LINUX-GCC程序
    树莓派 原理图 摄像头接口定义
    usb描述符详细讲解
    常用的算法思想
    STM32f407 DCMI方式驱动 OV2640
    linux echo命令-转
  • 原文地址:https://www.cnblogs.com/neopolitan/p/8010791.html
Copyright © 2011-2022 走看看