Language: C++

#include <bits/stdc++.h>

template<typename T>
void fill_all(T& ar,const T& v){
	ar=v;
}
template<typename T,size_t N,typename U>
void fill_all(T(& ar)[N],const U& v){
	for(auto&i:ar){fill_all(i,v);}
}


int w,h;
const int goal = 23;
const int empty = 24;

int graph[25][4][25];//????????????
int map[10][10];

const int nposmax = 6;
const int bitmax = 1<<21;
//bit????????????
int dp[nposmax][bitmax];
int func(int now, int bit){
	if(now==empty){return 0;}
	if(now==goal){
	#ifdef DEBUG
	std::cout<<"OUTg0:" << now <<' '<<bit<<':'<<((now==goal&&bit==0)?1:0)<<std::endl;
	#endif
		return ((now==goal&&bit==0)?1:0);
	}
	if(bit==0){
		for(auto& g:graph[now]){
			if(g[0] == goal){
	#ifdef DEBUG
	std::cout<<"OUTb0:" << now <<' '<<bit<<':'<<1<<std::endl;
	#endif
				return 1;
			}
		}
	#ifdef DEBUG
	std::cout<<"OUTb0:" << now <<' '<<bit<<':'<<0<<std::endl;
	#endif
		return 0;
	}
	
	if(bit<bitmax&&now<nposmax)if(dp[now][bit]>=0){return dp[now][bit];}
	int res = 0;
	#if 0
	for(int graph_num =0;graph_num<4;++graph_num){
		for(auto iter=graph[now][graph_num];*iter!=empty;++iter){
			if(bit&(1<<*iter)){
				res += func(*iter,bit&(~(1<<*iter)));
			}
			else{
				break;
			}
		}
	}
	#endif
	
	for(int graph_num =0;graph_num<4;++graph_num){
		{
			auto iter = &graph[now][0];
			if(bit&(1<<*iter)){
				res += func(*iter,bit&(~(1<<*iter)));
			}
			else{
				break;
			}
		}
	}
	
	if(bit<bitmax&&now<nposmax)return dp[now][bit]=res;
	return res;
}
int main()
{
	for(;;){
	fill_all(dp,-1);
	fill_all(map,empty);
	fill_all(graph,empty);
	std::cin>>w>>h;if(w==0&&h==0){break;}
	int count = 0;
	for(auto y=0;y<h;++y)for(auto x=0;x<w;++x){
		std::cin >> map[y][x];
		if(map[y][x]==0){
			map[y][x]=empty;
			continue;
		}
		else if(map[y][x]==1){
			map[y][x]=count++;
		}
		else if(map[y][x]==2){
			map[y][x]=goal;
		}
			auto pushback=[](int*g, int v){
				while(*g!=empty){++g;}*g=v;
			};
			auto iter = graph[map[y][x]][0];
			for(int ox=x-1;ox>=0;--ox){
				if(empty>map[y][ox]){
	#ifdef DEBUG
	std::cout <<"PASSx "<<x<<' '<<y<<"<->"<<ox<<' '<<y<<' '<<map[y][ox] <<"\n";
	#endif
					*(iter++) = map[y][ox];
					pushback(graph[map[y][ox]][2],map[y][x]);
	#ifdef DEBUG
	std::cout <<"graph "<<*(iter-1) <<' '<<map[y][x]<<"\n";
	#endif
				}
			}
			iter = graph[map[y][x]][1];
			for(int oy=y-1;oy>=0;--oy){
				if(empty>map[oy][x]){
	#ifdef DEBUG
	std::cout <<"PASSy "<<x<<' '<<y<<"<->"<<x<<' '<<oy<<' '<<map[oy][x]<<"\n";
	#endif
					*(iter++) = map[oy][x];
					pushback(graph[map[oy][x]][3],map[y][x]);
	#ifdef DEBUG
	std::cout <<"graph "<<*(iter-1) <<' '<<map[y][x]<<"\n";
	#endif
				}
			}
	}
	int bit = 0;
	while(--count>=0){bit<<=1;bit|=1;}
	#ifdef DEBUG
	std::cout<<bit<<std::endl;
	for(auto& g:graph[goal])for(auto iter=g;iter!=g+5;++iter){
	std::cout << *iter << ' ';
	}std::cout<<std::endl;
	for(auto& g:graph[4])for(auto iter=g;iter!=g+5;++iter){
	std::cout << *iter << ' ';
	}std::cout<<std::endl;
	for(auto& g:graph[3])for(auto iter=g;iter!=g+5;++iter){
	std::cout << *iter << ' ';
	}std::cout<<std::endl;
	#endif
	int res = 0;
	for(auto& arr : graph[goal]){
		for(auto iter=arr;*iter!=empty;++iter){
			res+=func(*iter,bit&(~(1<<*iter)));
		}
	}
	std::cout << res << std::endl;
	
	}
}

Compiler output:
a.cc: In function 'int func(int, int)':
a.cc:65:34: error: invalid operands of types 'int' and 'int [25]' to binary 'operator<<'
   65 |                         if(bit&(1<<*iter)){
      |                                 ~^~~~~~~
      |                                 |  |
      |                                 |  int [25]
      |                                 int
a.cc:66:59: error: invalid operands of types 'int' and 'int [25]' to binary 'operator<<'
   66 |                                 res += func(*iter,bit&(~(1<<*iter)));
      |                                                          ~^~~~~~~
      |                                                          |  |
      |                                                          |  int [25]
      |                                                          int