as #!/usr/bin/env python # encoding: utf-8 class wisdom(object): def __init__(self,n,g): self.n = n self.g = g def dist(self): #所有可能分配方案 if self.n == 1: yield [self.g] return for i in range(self.g, -1, -1):#步长-1 递减 for d in wisdom(self.n-1, self.g-i)…