Advertisement
alex0sunny

dfs

Jun 15th, 2022 (edited)
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.30 KB | None | 0 0
  1. def dfs(path, ars, combs):
  2.     pos = len(path)
  3.     if pos == len(ars):
  4.         combs.append(path)
  5.         return
  6.     for x in ars[pos]:
  7.         dfs(path+[x], ars, combs)
  8.  
  9. def gen_combs(ars):
  10.     combs = []
  11.     dfs([], ars, combs)
  12.     return combs
  13.  
  14. ars = [[1, 2, 3], [10, 20]]
  15. print(gen_combs(ars))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement