zoukankan      html  css  js  c++  java
  • POJ 1274

     1 #include<iostream>
     2 #include<stdio.h>
     3 #include <string.h>
     4 #include <vector>
     5 #define MAXN 251
     6 #define _clr(x) memset(x,0xff,sizeof(int)*MAXN)
     7 #define _clr(x) memset(x,0xff,sizeof(int)*MAXN) 
     8 
     9 using namespace std;
    10 
    11 int hungary(int m,int n,int mat[][MAXN],int* match1,int* match2);
    12 int _m[MAXN][MAXN];
    13 int match1[MAXN];
    14 int match2[MAXN];
    15 int main()
    16 {
    17     //freopen("acm.acm","r",stdin);
    18     int M;
    19     int N;
    20     int n;
    21     int i;
    22     int j;
    23 //    bool M_N;
    24     int s;
    25     while(cin>>M>>N)
    26     {
    27 //    if(M <= N)
    28 //        M_N = true;
    29     for(i = 0; i < MAXN; ++i)
    30     {
    31         memset(_m[i],0,sizeof(int)*MAXN);
    32     }
    33     for(i = 0; i < M; ++ i)
    34     {
    35         cin>>s;
    36         for(j = 0; j < s; ++ j)
    37         {
    38             cin>>n;
    39 //            if(M_N)
    40 //            {
    41                 _m[i][n-1] = 1;
    42 //            }
    43 //            else
    44 //            {
    45 //                _m[n-1][i] = 1;
    46 //            }
    47         }
    48     }
    49 //    if(M_N)
    50         cout<<hungary(M,N,_m,match1,match2)<<endl;
    51 //    else
    52 //        cout<<hungary(N,M,_m,match1,match2)<<endl;
    53     }
    54 }
    55 
    56 
    57 int hungary(int m,int n,int mat[][MAXN],int * match1,int* match2){
    58     int s[MAXN],t[MAXN],p,q,ret=0,i,j,k;
    59     for (_clr(match1),_clr(match2),i=0;i<m;ret+=(match1[i++]>=0))
    60         for (_clr(t),s[p=q=0]=i;p<=q&&match1[i]<0;p++)
    61             for (k=s[p],j=0;j<n&&match1[i]<0;j++)
    62                 if (mat[k][j]&&t[j]<0){
    63                     s[++q]=match2[j],t[j]=k;
    64                     if (s[q]<0)
    65                         for (p=j;p>=0;j=p)
    66                             match2[j]=k=t[j],p=match1[k],match1[k]=j;
    67                 }
    68     return ret;
    69 }

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

    技术网站地址: vmfor.com

  • 相关阅读:
    python变量及简单数据类型
    python函数小案例
    python字符串和列表小案例
    python循环输出
    Jmeter测试工具
    操作系统-进程管理~
    操作系统~
    组成原理第一章笔记~
    分时间段(年份或月份)统计,没有数字补0 Java(替代 MYSQL) 做法
    组成原理复习概略
  • 原文地址:https://www.cnblogs.com/gavinsp/p/4563355.html
Copyright © 2011-2022 走看看