题解 | #统计每个月兔子的总数#
统计每个月兔子的总数
https://www.nowcoder.com/practice/1221ec77125d4370833fd3ad5ba72395
我也是有病,写了个类,结果内存超了,这不就是斐波那契数吗
class rabbit: def __init__(self, id_, age_=0): self.id = id_ self.age = age_ if __name__ == "__main__": N = int(input()) rabbitLs = [rabbit(1)] for n in range(1, N + 1): idx = rabbitLs[-1].id bornRab = [] for rabt in rabbitLs: if rabt.age >= 2: idx += 1 bornRab.append(rabbit(idx, 1)) rabt.age += 1 rabbitLs.extend(bornRab) print(len(rabbitLs))