Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3372 Accepted Submission(s):
1997
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 const int MAX = 110; 7 int g[MAX][MAX],vis[MAX],link[MAX]; 8 int n,m,k; 9 int findx(int x) 10 { 11 for(int i = 1; i <= m; i++) //注意这是m 12 { 13 if(g[x][i] == 1 && vis[i] == 0) 14 { 15 vis[i] = 1; 16 if(link[i] == 0 || findx(link[i])) 17 { 18 link[i] = x; 19 return true; 20 } 21 } 22 } 23 return false; 24 } 25 int getsum() 26 { 27 int sum = 0; 28 memset(link,0,sizeof(link)); 29 for(int i = 1; i <= n; i++) 30 { 31 memset(vis,0,sizeof(vis)); 32 if(findx(i)) 33 sum++; 34 } 35 return sum; 36 } 37 int main() 38 { 39 int t = 0; 40 while(scanf("%d%d%d", &n,&m,&k) != EOF) 41 { 42 int x,y,sum = 0,important = 0; 43 memset(g,0,sizeof(g)); //初始化 44 for(int i = 0; i < k; i++) 45 { 46 scanf("%d%d",&x,&y); 47 g[x][y] = 1; 48 } 49 sum = getsum(); 50 51 for(int i = 1; i <= n; i++) 52 { 53 for(int j = 1; j <= m; j++) 54 { 55 if(g[i][j]) 56 { 57 g[i][j] = 0; 58 if(sum > getsum()) 59 important++; 60 g[i][j] = 1; 61 } 62 } 63 } 64 printf("Board %d have %d important blanks for %d chessmen.\n",++t,important,sum); 65 } 66 return 0; 67 }
原文:http://www.cnblogs.com/zhaopAC/p/5005293.html