1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| import sys
def distribute(giftNum,childNum): children = [[[0]*childNum]] for times in range(1,giftNum+1): children.append([]) for prob in range(len(children[times-1])): for tarChild in range(childNum): child = children[times-1][prob].copy() child[tarChild] += 1 if children[times].count(child) == 0: children[times].append(child) return children[giftNum]
if __name__ == "__main__": inputLine = sys.stdin.readline().strip().split(" ") inputLine = [int(str) for str in inputLine] n = inputLine[0] k = inputLine[1] distribution = distribute(n,k) print(len(distribution)) for prob in distribution: count = 0 for i in prob: print("*"*i,end='') count = count+1 if count < k: print("|",end='') print()
|