Skip to content

Instantly share code, notes, and snippets.

@irachex
Last active December 13, 2015 19:09
Show Gist options
  • Select an option

  • Save irachex/4960941 to your computer and use it in GitHub Desktop.

Select an option

Save irachex/4960941 to your computer and use it in GitHub Desktop.
cnt = {}
MAX_DEP = 10
def traverse(dep, i, size):
cnt[i] = cnt.get(i, 0) + 1
if dep >= MAX_DEP: return
for j in range(size):
traverse(dep + 1, i + j + 1, size + 1 - j)
traverse(0, 0, 1)
for i in range(8):
print i, cnt[i]
@irachex
Copy link
Copy Markdown
Author

irachex commented Feb 15, 2013

traverse(dep, i, size)表示遍历深度为dep,节点值为i,子节点数为size的节点

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment