Last active
August 29, 2015 14:09
-
-
Save chipbell4/4c3d6dc166d4e52f3581 to your computer and use it in GitHub Desktop.
Ken Ken Solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def memoize(func): | |
hashed_states = {} | |
def memoized_func(*args): | |
if args not in hashed_states: | |
hashed_states[args] = func(*args) | |
return hashed_states[args] | |
return memoized_func | |
@memoize | |
def F(n, k, c): | |
if n < 0: | |
return 0 | |
if k is 0 and n is 0: | |
return 1 | |
if k is 0 and n is not 1: | |
return 0 | |
if n is 0 and k is not 0: | |
return 0 | |
return k * sum( F(n-i, k-1, i-1) for i in range(1, min(n, c)+1) ) | |
cases = int(input()) | |
for case in range(cases): | |
n, k, c = map(int, input().strip().split()) | |
print(n, k, c, F(n, k, c)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment