度小满 9.13 笔试情况(风控模型岗)

两道题:
1.迷宫花费最少时间
2.最大上升子序列的 方案
第一题:不知道从哪里终止条件,所以设了一个dfs的深度上限,好在AC了,有知道的告知一下
def dfs(x,y,cost,depth,max_depth):
    if depth > max_depth:
        return
    cost += int(MAP[x][y])
    if x==N-1 and y==N-1:
        res.append(cost)
        return
    else:
        if x-1>=0 and MAP[x-1][y] != '*':
            dfs(x-1,y,cost,depth+1,max_depth)
        if x+1<=N-1 and MAP[x+1][y] != '*':
            dfs(x+1,y,cost,depth+1,max_depth)
        if y-1>=0 and MAP[x][y-1] != '*':
            dfs(x,y-1,cost,depth+1,max_depth)
        if y+1<=N-1 and MAP[x][y+1] != '*':
            dfs(x,y+1,cost,depth+1,max_depth)
        return
if __name__ == '__main__':
    N,K = list(map(int,input().split()))
    MAP = []
    for i in range(N):
        line = input()
        line = line.replace('1','*').replace('0','1').replace('#',str(K))
        MAP.append([c for c in line])
    res = []
    dfs(0,0,0,0,4*N)
    if res == []:
        print('No solution')
    else:
        print(min(res)-1)

#度小满笔试##笔试题目##度小满#
全部评论
天坛怎么写,我就一个公式咋才a 70% 多
1 回复
分享
发布于 2020-09-13 21:48
就我一个第一道是天坛?
点赞 回复
分享
发布于 2020-09-13 21:41
联易融
校招火热招聘中
官网直投
第二道剑指原题,但是不知道怎么输入迷宫,唉太可惜了
点赞 回复
分享
发布于 2020-09-13 21:42
面试完等消息群:735945121
点赞 回复
分享
发布于 2020-09-14 15:04

相关推荐

头像
不愿透露姓名的神秘牛友
04-21 09:18
已编辑
徐工重型 振动噪声工程师 第一年总包17.6w,单休 硕士211
点赞 评论 收藏
转发
2 5 评论
分享
牛客网
牛客企业服务