标签:sea php 攻击 namespace can memset mem 表示 gif
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4394 Accepted Submission(s): 2594
1 //将棋盘横纵坐标分别看做二分图左右集合,能放最多车的数量就是二分图的最大匹配,找重要点就枚举看去掉某一点最大匹配会不会少。竟然不会超时!!!! 2 #include<iostream> 3 #include<cstdio> 4 #include<cstring> 5 using namespace std; 6 int mp[102][102],vis[102],link[102]; 7 int Mu,Mv,n,m,k; 8 int dfs(int x) 9 { 10 for(int i=1;i<=Mv;i++) 11 { 12 if(!vis[i]&&mp[x][i]) 13 { 14 vis[i]=1; 15 if(link[i]==-1||dfs(link[i])) 16 { 17 link[i]=x; 18 return 1; 19 } 20 } 21 } 22 return 0; 23 } 24 int Maxcon() 25 { 26 int ans=0; 27 memset(link,-1,sizeof(link)); 28 for(int i=1;i<=Mu;i++) 29 { 30 memset(vis,0,sizeof(vis)); 31 if(dfs(i)) ans++; 32 } 33 return ans; 34 } 35 int main() 36 { 37 int t=1,a,b; 38 while(scanf("%d%d%d",&n,&m,&k)!=EOF) 39 { 40 memset(mp,0,sizeof(mp)); 41 for(int i=0;i<k;i++) 42 { 43 scanf("%d%d",&a,&b); 44 mp[a][b]=1; 45 } 46 Mu=n;Mv=m; 47 int ans=Maxcon(),tem=0; 48 for(int i=1;i<=n;i++) 49 for(int j=1;j<=m;j++) 50 { 51 if(!mp[i][j]) continue; 52 mp[i][j]=0; 53 if(ans>Maxcon()) tem++; 54 mp[i][j]=1; 55 } 56 printf("Board %d have %d important blanks for %d chessmen.\n",t++,tem,ans); 57 } 58 return 0; 59 }
标签:sea php 攻击 namespace can memset mem 表示 gif
原文地址:http://www.cnblogs.com/--ZHIYUAN/p/6068575.html