#include #include int map[11][11],houseCount,rootCount,gy,gx; int dxs[]={1,0,-1,0}; int dys[]={0,1,0,-1}; int houseMap[11][11]; int w,h; struct root{ int memo,nowP;//memoは訪れた家を1bit単位で管理する bool operator<(const root r)const{ if(memo!=r.memo) return memo memos; int saiki(int sx,int sy,int deep,int memo){ if(deep==houseCount){ return 1; } int c; if(deep==houseCount-1){ c=2; }else{ c=1; } int nx,ny,sum=0; root r; r.memo=memo; for(int i=0;i<4;i++){ for(int j=1;j<11;j++){ nx=sx+dxs[i]*j; ny=sy+dys[i]*j; if(nx<0 || w<=nx || ny<0 || h<=ny) break; if(map[ny][nx]==c){ r.nowP=houseMap[ny][nx]; if(memos.find(r)==memos.end()){ map[ny][nx]=-c; memos[r]=saiki(nx,ny,deep+1,memo|(1<