“李白街上走,提壶去买酒,遇店加一倍,见花喝一斗”,途中,遇见5次店,见了10此花,壶中原有2斗酒,最后刚好喝完酒,要求最后遇见的是花,求可能的情况有多少种?请帮我写出计算的python代码

bluesky1年前 ⋅ 770 阅读
from itertools import combinations 

total = 5 + 10  # 总共店和花的数量
drink = 2 # 壶中原有2斗酒
# 穷举出所有可能情况
points = list(combinations(list(range(total)), drink))
res = 0 # 记录符合条件的可能情况
for point in points:
    if point[-1] >= 5:
        res += 1
        
print('一共有{}种符合条件的可能情况'.format(res))

全部评论: 0

    相关推荐