滴滴21号笔试题2ac
matrix=['CHIA', 'CANT', 'GRAC', 'BBDE'] n=4 ans=[] mem=['C','H','I','N','A'] dire=[[-1,0],[1,0],[0,-1],[0,1]] def dfs(x,y,iter): # nonlocal ans #nonlocal ans if iter==5: ans.append(1) return for i in range(4): nx,ny=x+dire[i][0],y+dire[i][1] print(nx,ny,n) if 0<=nx<n and 0<=ny<n and matrix[nx][ny]==mem[iter]: dfs(nx,ny,iter+1) for i in range(n): for j in range(n): if matrix[i][j]=='C': dfs(i,j,1) print(ans)
# def fibo(n): # ans = [1, 1] # if n <= 2: return ans # # for i in range(2, n): # ans.append(ans[-2] + ans[-1]) # return ans # # # n = int(input()) # res = [[0 for _ in range(n)] for _ in range(n)] # nums = fibo(n ** 2)[::-1] # i, j = 0, 0 # iter = 0 # l, r, t, b = 0, n - 1, 0, n - 1 # if n==1: # print(1,'do') # elif n%2==0 and n!=1: # # while iter < n ** 2 - 1: # while j <= r: # res[i][j] = nums[iter] # j += 1 # iter += 1 # j -= 1 # t += 1 # iter -= 1 # # while i <= b: # res[i][j] = nums[iter] # i += 1 # iter += 1 # i -= 1 # r -= 1 # iter -= 1 # # while j >= l: # res[i][j] = nums[iter] # j -= 1 # iter += 1 # j += 1 # b -= 1 # iter -= 1 # # while i >= t: # res[i][j] = nums[iter] # i -= 1 # iter += 1 # i += 1 # l += 1 # iter -= 1 # else: # while iter < n ** 2-2 : # while j <= r: # res[i][j] = nums[iter] # j += 1 # iter += 1 # j -= 1 # t += 1 # iter -= 1 # # # break # while i <= b: # res[i][j] = nums[iter] # i += 1 # iter += 1 # i -= 1 # r -= 1 # iter -= 1 # # while j >= l: # res[i][j] = nums[iter] # j -= 1 # iter += 1 # j += 1 # b -= 1 # iter -= 1 # # while i >= t: # res[i][j] = nums[iter] # i -= 1 # iter += 1 # i += 1 # l += 1 # if iter==n**2-1: # res[n//2][n//2]=nums[iter] # iter -= 1 # # #if iter== # # # for i in range(n): # print(" ".join(str(j) for j in res[i]))滴滴笔试 第一题写的挺烂的,因为ac了就没调整。
#滴滴##笔试题目#