POJ 1274
2015-06-09 13:54
351 查看
#include<iostream> #include<stdio.h> #include <string.h> #include <vector> #define MAXN 251 #define _clr(x) memset(x,0xff,sizeof(int)*MAXN) #define _clr(x) memset(x,0xff,sizeof(int)*MAXN) using namespace std; int hungary(int m,int n,int mat[][MAXN],int* match1,int* match2); int _m[MAXN][MAXN]; int match1[MAXN]; int match2[MAXN]; int main() { //freopen("acm.acm","r",stdin); int M; int N; int n; int i; int j; // bool M_N; int s; while(cin>>M>>N) { // if(M <= N) // M_N = true; for(i = 0; i < MAXN; ++i) { memset(_m[i],0,sizeof(int)*MAXN); } for(i = 0; i < M; ++ i) { cin>>s; for(j = 0; j < s; ++ j) { cin>>n; // if(M_N) // { _m[i][n-1] = 1; // } // else // { // _m[n-1][i] = 1; // } } } // if(M_N) cout<<hungary(M,N,_m,match1,match2)<<endl; // else // cout<<hungary(N,M,_m,match1,match2)<<endl; } } int hungary(int m,int n,int mat[][MAXN],int * match1,int* match2){ int s[MAXN],t[MAXN],p,q,ret=0,i,j,k; for (_clr(match1),_clr(match2),i=0;i<m;ret+=(match1[i++]>=0)) for (_clr(t),s[p=q=0]=i;p<=q&&match1[i]<0;p++) for (k=s[p],j=0;j<n&&match1[i]<0;j++) if (mat[k][j]&&t[j]<0){ s[++q]=match2[j],t[j]=k; if (s[q]<0) for (p=j;p>=0;j=p) match2[j]=k=t[j],p=match1[k],match1[k]=j; } return ret; }
相关文章推荐
- h264视频编码的MP4格式视频无法在网页中的adobe flash player中播放
- oracle11g分区表
- python 抽象方法 抽象类实现
- 命令jps
- Ubuntu change default sh from dash to bash
- 判断listview滚动,点击回到顶部
- java线程间的协调
- Spring-data-jpa+Hibernate 各种缓存的配置
- 【Android】ListView动态视图显示不全
- HTML5 Canvas Tutorial
- POJ 1270
- POJ 1260
- POJ 1273
- iOS开发常用快捷键
- 【资料整理】cisco [cli, static, rip, eigrp, ospf]
- c#语法总结1
- kindeditor html代码过滤(丢失某些HTML标签)
- Java线程_wait,sleep,notify,notifyall,join
- catch the cow 抓住小黄牛
- Oracle 工艺结构