给n*n的方格图铺满1*2 的长条,且某些位置不能铺,问最多能放多少个长条
#include <iostream> #include<queue> #include <vector> #include <cstring> using namespace std; const int N =110 ,M=N*N; #define int long long vector<int> g[M]; void add_(int x,int y){ g[x].push_back(y); } int n,vis[M],mch[M]; bool dfs(const int x,const int cas){ if(vis[x]==cas) return 0; vis[x]=cas; for(int i=0;i<g[x].size();i++){ int y=g[x][i]; if(mch[y]==0||dfs(mch[y],cas)){ mch[y]=x; return 1; } } return 0; } int K,ban[N][N],b[N][N],id[N][N]; int D[5][2]={{1,0},{-1,0},{0,1},{0,-1}}; bool OK(int x,int y){ return x>0&&x<=n&&y>0&&y<=n; } signed main(){ int i,j,x,y; cin>>n>>K; for(i=1;i<=K;i++){ cin>>x>>y; ban[x][y]=1; } for(i=1;i<=n;i++) for(j=1;j<=n;j++){ if(ban[i][j]) continue; if((i+j)&1) b[i][j]=1; else b[i][j]=0; id[i][j]=(i-1)*n+j; for(int k=0;k<4;k++){ int xx=D[k][0]+i,yy=D[k][1]+j; if(OK(xx,yy)==0) continue; if(ban[xx][yy]) continue; int id2=(xx-1)*n+yy; if(b[xx][yy]!=b[i][j]) add_(id[i][j],id2); } } int ans=0; for(i=1;i<=n;i++) for(j=1;j<=n;j++){ if(b[i][j] &&ban[i][j]==0&& dfs(id[i][j],id[i][j])) ans++; } cout<<ans<<endl; }
标签:cas,372,const,vis,int,long,include,棋盘,AcWing From: https://www.cnblogs.com/towboa/p/17135432.html