poj 2226(最小点覆盖集)
嘛。。稍微有一点变形,相当于每隔一段草,一行或一列就成新的了,用rnum,cnum记录一下就好了。
# include <cstdio> # include <cstring> # include <algorithm> # include <iostream> using namespace std; char map[100][100]; int mp[500][500],f[500],flag[500],r,c,sum,rnum,cnum,maxn,col[100][100]; int find(int i) { int j; for (j=1;j<=cnum;++j) { if (mp[i][j]&&!flag[j]) { flag[j] = 1; if (!f[j]||find(f[j])) { f[j] = i; return 1; } } } return 0; } int main() { int i,j; char str[100]; while (~scanf("%d%d",&r,&c)) { sum = 0;rnum = 1;cnum = c; memset(mp,0,sizeof(mp)); memset(f,0,sizeof(f)); for (i=1;i<=r;++i) { scanf("%s",str+1); for (j=1;j<=c;++j) { map[i][j] = str[j]; if (str[j]=='*') { if (map[i][j-1] == '.') ++rnum; if (i==1) col[i][j] = j; else if (map[i-1][j] == '.') col[i][j] = (++cnum); else col[i][j] = col[i-1][j]; mp[rnum][col[i][j]] = 1; } } rnum++; } for (i=1;i<=rnum;++i) { memset(flag,0,sizeof(flag)); sum += find(i); } printf("%d\n",sum); } return 0; }