Skip to content

Instantly share code, notes, and snippets.

@st0le
Created June 20, 2013 02:31
Show Gist options
  • Save st0le/5819892 to your computer and use it in GitHub Desktop.
Save st0le/5819892 to your computer and use it in GitHub Desktop.
minhop dfs
def minhops_dfs(lst):
sz = len(lst)
min_hop = [0] * sz
def dfs(index,s,hops,min_hop):
if index >= sz:
if len(min_hop) > s:
min_hop[:] = hops
#min_hop.extend(hops)
elif s > len(min_hop):
pass
else:
hops.append(lst[index])
for i in xrange(1,lst[index] + 1):
dfs(index + i, s + 1,hops,min_hop)
hops.pop()
dfs(0,0,[],min_hop)
return len(min_hop)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment