n = 0
def recursive(u,v):
global ans
if(u == n-1 and v == n-1):
ans += 1
return
data[u][v] = 1
if(u-1 >= 0 and data[u-1][v] == 0):
recursive(u-1,v)
if(u+1 < n and data[u+1][v] == 0):
recursive(u+1,v)
if(v-1 >= 0 and data[u][v-1] == 0):
recursive(u,v-1)
if(v+1 < n and data[u][v+1] == 0):
recursive(u,v+1)
data[u][v] = 0
return
t = int(input())
for _ in range(t):
n = int(input())
data = []
for i in range(n):
data.append(list(map(int,input().split())))
ans = 0
recursive(0,0)
print(ans)
def recursive(u,v):
global ans
if(u == n-1 and v == n-1):
ans += 1
return
data[u][v] = 1
if(u-1 >= 0 and data[u-1][v] == 0):
recursive(u-1,v)
if(u+1 < n and data[u+1][v] == 0):
recursive(u+1,v)
if(v-1 >= 0 and data[u][v-1] == 0):
recursive(u,v-1)
if(v+1 < n and data[u][v+1] == 0):
recursive(u,v+1)
data[u][v] = 0
return
t = int(input())
for _ in range(t):
n = int(input())
data = []
for i in range(n):
data.append(list(map(int,input().split())))
ans = 0
recursive(0,0)
print(ans)
No comments:
Post a Comment