Advertisement
Guest User

Untitled

a guest
May 24th, 2018
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. def count_binary_trees(N):
  2.   binary_size = [0]*(N+1)
  3.   binary_size[1] = 1
  4.  
  5.   def count_binary(N):
  6.     if N < 0:
  7.       return 0
  8.     if binary_size[N]:
  9.       return binary_size[N]
  10.  
  11.     left_size, right_size = 1, N-2
  12.     counter = 0
  13.     while right_size > 0:
  14.       counter += count_binary(left_size)*count_binary(right_size)
  15.       left_size += 1
  16.       right_size -= 1
  17.  
  18.     binary_size[N] = counter
  19.     return  counter
  20.  
  21.   return count_binary(N)
  22.  
  23.  
  24. print(count_binary_trees(11))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement