Language: C++

#include <bits/stdc++.h>
using namespace std;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int W, H, N = 0;
int mas[11][11];
int X[25], Y[25];
bool isin(int y, int x)
{
    return (y >= 0 && x >= 0 && y < H && x < W);
}
int dfs(int y, int x, int bit)
{
    int ret = 0;
    if(bit == 0) return (1);
    for(int i = 0; i < 4; i++) {
        int ny = y + dy[i], nx = x + dx[i];
        while(isin(ny, nx) && (mas[ny][nx] < 0 || (bit != (1 << N) && mas[ny][nx] == N) || (bit & ~(1 << mas[ny][nx])) == bit)) ny += dy[i], nx += dx[i];
        if(isin(ny, nx)) ret += dfs(ny, nx, bit & ~(1 << mas[ny][nx]));
    }
    return (ret);
}

int main()
{
    int px, py;
    cin >> W >> H;
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            cin >> mas[i][j];
            if(mas[i][j] == 0) mas[i][j] = -1;
            else if(mas[i][j] == 1) mas[i][j] = N, N++;
            else py = i, px = j;
        }
    }
    mas[py][px] = N;
    cout << dfs(py, px, (1 << (N + 1)) - 1) << endl;
    return (0);
}
bash-4.3(leia):~/syoribu/JOI/2017/sp/pr
572:{ei1629}$ bc
4^7 * 2^16
1073741824
cat ^Cquit
bash-4.3(leia):~/syoribu/JOI/2017/sp/pr
573:{ei1629}$ cat Reindeer_with_no_sense_of_direction.cpp
#include <bits/stdc++.h>
using namespace std;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int W, H, N = 0;
int mas[11][11];
bool isin(int y, int x)
{
    return (y >= 0 && x >= 0 && y < H && x < W);
}
int dfs(int y, int x, int bit)
{
    int ret = 0;
    if(bit == 0) return (1);
    for(int i = 0; i < 4; i++) {
        int ny = y + dy[i], nx = x + dx[i];
        while(isin(ny, nx) && (mas[ny][nx] < 0 || (bit != (1 << N) && mas[ny][nx] == N) || (bit & ~(1 << mas[ny][nx])) == bit)) ny += dy[i], nx += dx[i];
        if(isin(ny, nx)) ret += dfs(ny, nx, bit & ~(1 << mas[ny][nx]));
    }
    return (ret);
}

int main()
{
    int px, py;
    while(cin >> W >> H, W || H) {
        for(int i = 0; i < H; i++) {
            for(int j = 0; j < W; j++) {
                cin >> mas[i][j];
                if(mas[i][j] == 0) mas[i][j] = -1;
                else if(mas[i][j] == 1) mas[i][j] = N, N++;
                else py = i, px = j;
            }
        }
        mas[py][px] = N;
        cout << dfs(py, px, (1 << (N + 1)) - 1) << endl;
    }
    return (0);
}



Compiler output:
a.cc:40:1: error: 'bash' does not name a type
   40 | bash-4.3(leia):~/syoribu/JOI/2017/sp/pr
      | ^~~~
a.cc:41:13: error: '$' does not name a type
   41 | 572:{ei1629}$ bc
      |             ^
a.cc:46:13: error: '$' does not name a type
   46 | 573:{ei1629}$ cat Reindeer_with_no_sense_of_direction.cpp
      |             ^
a.cc:49:11: error: redefinition of 'const int dy []'
   49 | const int dy[] = {1, 0, -1, 0};
      |           ^~
a.cc:3:11: note: 'const int dy [4]' previously defined here
    3 | const int dy[] = {1, 0, -1, 0};
      |           ^~
a.cc:50:11: error: redefinition of 'const int dx []'
   50 | const int dx[] = {0, 1, 0, -1};
      |           ^~
a.cc:4:11: note: 'const int dx [4]' previously defined here
    4 | const int dx[] = {0, 1, 0, -1};
      |           ^~
a.cc:51:5: error: redefinition of 'int W'
   51 | int W, H, N = 0;
      |     ^
a.cc:5:5: note: 'int W' previously declared here
    5 | int W, H, N = 0;
      |     ^
a.cc:51:8: error: redefinition of 'int H'
   51 | int W, H, N = 0;
      |        ^
a.cc:5:8: note: 'int H' previously declared here
    5 | int W, H, N = 0;
      |        ^
a.cc:51:11: error: redefinition of 'int N'
   51 | int W, H, N = 0;
      |           ^
a.cc:5:11: note: 'int N' previously defined here
    5 | int W, H, N = 0;
      |           ^
a.cc:52:5: error: redefinition of 'int mas [11][11]'
   52 | int mas[11][11];
      |     ^~~
a.cc:6:5: note: 'int mas [11][11]' previously declared here
    6 | int mas[11][11];
      |     ^~~
a.cc:53:6: error: redefinition of 'bool isin(int, int)'
   53 | bool isin(int y, int x)
      |      ^~~~
a.cc:8:6: note: 'bool isin(int, int)' previously defined here
    8 | bool isin(int y, int x)
      |      ^~~~
a.cc:57:5: error: redefinition of 'int dfs(int, int, int)'
   57 | int dfs(int y, int x, int bit)
      |     ^~~
a.cc:12:5: note: 'int dfs(int, int, int)' previously defined here
   12 | int dfs(int y, int x, int bit)
      |     ^~~
a.cc:69:5: error: redefinition of 'int main()'
   69 | int main()
      |     ^~~~
a.cc:24:5: note: 'int main()' previously defined here
   24 | int main()
      |     ^~~~