百度 笔试爬山求指教
用这种递归的方式做,为什么只有80%,请问有什么情况没考虑到
inx =raw_input().split() #print inx n = int(inx[0]) #n行 m = int(inx[1]) #m列 ins = raw_input().split() sx = int(ins[0])-1 #起始位置 sy = int(ins[1])-1 #print(n,m,sx,sy) l = [] for o in range(n): l.append(raw_input().split()) #矩阵赋值 class a(object): dx = [0,0,1,-1] #四种走法 dy = [1,-1,0,0] maxhigh = 0 def go(self,l,sx,sy): curhigh = int(l[sx][sy]) if curhigh>self.maxhigh: self.maxhigh = curhigh for x,y in zip(self.dx,self.dy): if sx+x>=0 and sx+x<m and sy+y>=0 and sy+y<n: #判断边界 nextx ,nexty = sx+x,sy+y if int(l[nextx][nexty])>curhigh: #下一步海拔高就走到那一步 sx ,sy= nextx,nexty self.go(l,sx,sy) else: continue return self.maxhigh b = a() print b.go(l,sx,sy)#百度#