Test instructions to cover the ' # ' in the matrix with 1*2 planks (only ' # ' to cover the planks), and ask for up to a few planks to cover
The # is abstracted as a two point, a plank is a match, note that the final result is divided by 2.
Sample Input
16.......##....##.......#.....## ...
Sample Outputcase 1:3
1#include <stdio.h>2#include <string.h>3 Const intmaxn= +;4 Charmap[610][610];5 inttt[610][610];6 intUN,VN;//Number of U,v7 intG[MAXN][MAXN];8 intLINKER[MAXN];9 BOOLUSED[MAXN];Ten BOOLDfsintu) One { A intv; - for(v=0; v<vn;v++) - if(g[u][v]&&!Used[v]) the { -used[v]=true; - if(linker[v]==-1||DFS (Linker[v])) - { +linker[v]=u; - return true; + } A } at return false; - } - intHungary () - { - intres=0; - intu; inmemset (linker,-1,sizeof(linker)); - for(u=0; u<un;u++) to { +memset (Used,0,sizeof(used)); - if(Dfs (U)) res++; the } * returnRes; $ } Panax Notoginseng - intMain () the { + intT; A intN; thescanf"%d",&T); + intIcase=0; - inttmp; $ while(t--) $ { -icase++; -scanf"%d",&n); the -tmp=0;Wuyi for(intI=0; i<n;i++) the { -scanf"%s",&map[i]); Wu for(intj=0; j<n;j++) - if(map[i][j]=='#') tt[i][j]=tmp++; About } $Memset (G,0,sizeof(g)); -un=vn=tmp; - for(intI=0; i<n;i++) - for(intj=0; j<n;j++) A { + if(map[i][j]!='#')Continue; the if(i>0&&map[i-1][j]=='#') g[tt[i][j]][tt[i-1][j]]=1; - if(i<n-1&&map[i+1][j]=='#') g[tt[i][j]][tt[i+1][j]]=1; $ if(j>0&&map[i][j-1]=='#') g[tt[i][j]][tt[i][j-1]]=1; the if(j<n-1&&map[i][j+1]=='#') g[tt[i][j]][tt[i][j+1]]=1; the } the the intres=Hungary (); -printf"Case %d:%d\n", icase,res/2); in } the return 0; the}
HDU 41,852-point map matching