Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n = int(input())
- DP = []
- for i in range(n+2):
- dp_row = [0] * (n+2)
- DP.append(dp_row)
- DP[1][1] = 1
- for i in range(1,n):
- for j in range(1,i+1):
- # Create a new component
- DP[i+1][j+1] += DP[i][j] * ( j + 1 )
- # Add at the beggining or the end of a component
- DP[i+1][j] += DP[i][j] * ( 2 * j )
- # Merge two existing components
- DP[i+1][j-1] += DP[i][j] * ( j - 1 )
- print( DP[n][1] )
- # Isn't this the most amazing code to compute n! you've ever seen :)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement