标签:mem 而且 des ble input sizeof 代码 c代码 php
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 21121 Accepted Submission(s): 9154
题目大意:有m个女生,n个男生一起去坐过山车,每个女生都有自己的想法,根据题中给定的数据输出最多可以组成多少对。
解题思路:直接跑一边匈牙利。
AC代码:
1 #include <stdio.h> 2 #include <string.h> 3 4 int n,m; 5 int line[510][510],used[510],match[510]; 6 int dfs(int x) 7 { 8 for (int i = 1; i <= n; i ++) 9 { 10 if (line[x][i] && !used[i]) 11 { 12 used[i] = 1; 13 if (match[i] == -1 || dfs(match[i])) 14 { 15 match[i] = x; 16 return 1; 17 } 18 } 19 } 20 return 0; 21 } 22 int f() 23 { 24 int sum = 0; 25 for (int i = 1; i <= m; i ++) 26 { 27 memset(used,0,sizeof(used)); 28 sum += dfs(i); 29 } 30 return sum; 31 } 32 int main () 33 { 34 int k,i,a,b; 35 while (scanf("%d",&k),k) 36 { 37 scanf("%d%d",&m,&n); 38 memset(match,-1,sizeof(match)); 39 memset(line,0,sizeof(line)); 40 for (i = 0; i < k; i ++) 41 { 42 scanf("%d%d",&a,&b); 43 line[a][b] = 1; 44 } 45 printf("%d\n",f()); 46 } 47 return 0; 48 }
标签:mem 而且 des ble input sizeof 代码 c代码 php
原文地址:http://www.cnblogs.com/yoke/p/6612452.html