标签:无法 ini 描述 style cst include 问题 print memory
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1281
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
1 #include<cstdio> 2 #include<cstring> 3 #include<vector> 4 #define MAX 203 5 using namespace std; 6 int n,m,k; 7 int edge[MAX][MAX]; 8 int matching[MAX]; 9 int vis[MAX]; 10 void init(){memset(edge,0,sizeof(edge));} 11 void add_edge(int u,int v){edge[u][v]=edge[v][u]=1;} 12 bool dfs(int u) 13 { 14 for(int v=1;v<=n+m;v++) 15 { 16 if(!edge[u][v]) continue; 17 if (!vis[v]) 18 { 19 vis[v]=1; 20 if(!matching[v] || dfs(matching[v])) 21 { 22 matching[v]=u; 23 matching[u]=v; 24 return true; 25 } 26 } 27 } 28 return false; 29 } 30 int hungarian() 31 { 32 int ret=0; 33 memset(matching,0,sizeof(matching)); 34 for(int i=1;i<=n;i++) 35 { 36 if(!matching[i]) 37 { 38 memset(vis,0,sizeof(vis)); 39 if(dfs(i)) ret++; 40 } 41 } 42 return ret; 43 } 44 int mp[103][103],match[MAX][MAX]; 45 int main() 46 { 47 int kase=0; 48 while(scanf("%d%d%d",&n,&m,&k)!=EOF) 49 { 50 memset(mp,0,sizeof(mp)); 51 for(int i=1,r,c;i<=k;i++) 52 { 53 scanf("%d%d",&r,&c); 54 mp[r][c]=1; 55 } 56 57 init(); 58 for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(mp[i][j]) add_edge(i,j+n); 59 int max_match=hungarian(); 60 61 int cnt=0; 62 memset(match,0,sizeof(match)); 63 for(int i=1;i<=n+m;i++) for(int j=n+1;j<=n+m;j++) if(matching[i]==j && matching[j]==i) match[i][j]=1; 64 for(int i=1;i<=n+m;i++) 65 { 66 for(int j=n+1;j<=n+m;j++) 67 { 68 if(match[i][j]) 69 { 70 edge[i][j]=0; 71 if(hungarian()<max_match) cnt++; 72 edge[i][j]=1; 73 } 74 } 75 } 76 77 printf("Board %d have %d important blanks for %d chessmen.\n",++kase,cnt,max_match); 78 } 79 }
标签:无法 ini 描述 style cst include 问题 print memory
原文地址:http://www.cnblogs.com/dilthey/p/7663065.html