• POJ 1466


     1 #include<iostream>
     2 #include<stdio.h>
     3 #define MAXN 505
     4 using namespace std;
     5 
     6 int edge[MAXN][MAXN];
     7 int match[MAXN];
     8 bool ck[MAXN];
     9 
    10 int hungary(int num1,int num2);
    11 bool search_dfs(int num1,int num2,int value);
    12 
    13 int main()
    14 {
    15     //freopen("acm.acm","r",stdin);
    16     int num;
    17     int i;
    18     int j;
    19     int u;
    20     int v;
    21     int s;
    22     int index;
    23     while(scanf("%d",&num) != EOF)
    24     {
    25         for(i = 0; i < num; ++ i)
    26         {
    27             edge[i][0] = -1;
    28         }
    29         for(i = 0; i < num; ++ i)
    30         {
    31             scanf("%d",&u);
    32             getchar();
    33             getchar();
    34             getchar();    
    35             scanf("%d",&s);
    36             getchar();
    37             getchar();
    38             index = 0;
    39             for(j = 0; j < s; ++ j)
    40             {
    41                 scanf("%d",&v);
    42                 edge[u][index ++] = v;
    43                 edge[u][index] = -1;
    44             }
    45         }
    46         cout<<num - hungary(num,num)/2<<endl;
    47     }
    48 }
    49 
    50 int hungary(int num1,int num2)
    51 {
    52     memset(match,-1,sizeof(match));
    53     int i;
    54     int sum = 0;
    55     for(i = 0; i < num1; ++ i)
    56     {
    57         memset(ck,false,sizeof(ck));
    58         if(search_dfs(num1,num2,i))
    59             ++ sum;
    60     }
    61     return sum;
    62 }
    63 bool search_dfs(int num1,int num2,int value)
    64 {
    65     int i;
    66     int t;
    67     i = 0;
    68     while(edge[value][i] != -1)
    69     {
    70         if(!ck[edge[value][i]])
    71         {
    72             ck[edge[value][i]] = true;
    73             t = match[edge[value][i]];
    74             match[edge[value][i]] = value;
    75             if(t == -1 || search_dfs(num1,num2,t))
    76                 return true;
    77             match[edge[value][i]] = t;
    78         }
    79         ++ i;
    80     }
    81     return false;
    82 }

    关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。 

    技术网站地址: vmfor.com

  • 相关阅读:
    day1 instance,round,divmod,imput, 字符串
    Django中如何将javascript中的变量传给位于javascript内的{% url %}中的参数?
    demo_33 评论发布弹窗实现
    demo_32 富文本渲染
    demo_31 详情页面数据初始化
    demo_30 内容预加载
    demo_29 详情页页面展示
    demo_28 使用自定义事件同步数据
    demo_27 保存标签页数据
    demo_26 编辑标签页
  • 原文地址:https://www.cnblogs.com/gavinsp/p/4563404.html
Copyright © 2020-2023  润新知