//是象棋里的车 符合二分匹配 # include<stdio.h> # include<algorithm> # include<string.h> using namespace std; int n,m,pp[110][110],map[110],vis[110]; int bfs(int x) { for(int i=1;i<=m;i++) { if(!vis[i]&&pp[x][i]) { vis[i]=1; if(!map[i]||bfs(map[i])) { map[i]=x; return 1; } } } return 0; } int f() { int a=0; memset(map,0,sizeof(map)); for(int i=1;i<=n;i++) { memset(vis,0,sizeof(vis)); if(bfs(i)) a++; } return a; } int main() { int i,j,k,cot1=0,ans,a,b; while(~scanf("%d%d%d",&n,&m,&k)) { memset(pp,0,sizeof(pp)); for(i=0;i<k;i++) { scanf("%d%d",&a,&b); pp[a][b]=1; } int cot=f(); ans=0; for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { if(pp[i][j])//判断是否为重要点 { pp[i][j]=0; if(f()<cot) ans++; pp[i][j]=1; } } } printf("Board %d have %d important blanks for %d chessmen.\n",++cot1,ans,cot); } return 0; }
hdu 1281 棋盘游戏 (二分匹配),布布扣,bubuko.com
原文:http://blog.csdn.net/lp_opai/article/details/38418551