题解 | #统计每个月兔子的总数#
统计每个月兔子的总数
http://www.nowcoder.com/practice/1221ec77125d4370833fd3ad5ba72395
#使用三个字典分别记录每个月份对应的成年兔子数,幼年兔子数和总数,然后通过找到的规律进行推导,一直推导到当前月份;
#规律为:幼年兔子数等于两个月前兔子的总数加三个月前兔子的总数(2个月和3个月前生的兔子生出的兔子都未满2个月,属于幼年)
#成年兔子的总数为两个月前兔子的总数;兔子的总数=成年兔子数+幼年兔子数
ip_num, i= int(input()), 3
count_adult = {0:0,1:0,2:0}
count_baby = {0:0,1:0,2:0}
count_all = {0:0,1:1,2:1}
if ip_num >= 3:
while i <= ip_num:
count_baby[i] = count_all[i-2] + count_all[i-3]
count_adult[i] = count_all[i-2]
count_all[i] = count_baby[i] + count_adult[i]
i += 1
print(count_all[ip_num])