问:四个人玩牌,去掉大小王,一个人拿牌的组合有多少种可能
方法一:DFS
# 牌的组合数.常识:13*4+2=54 张牌。每一类大小可以拿的张数有:0, 1, 2, 3, 4。问:四个人玩牌,一个人拿牌的组合数有多少种 count = 0 card_num = 0 def num_conbinations(): dfs(0) print(count) def dfs(card_size): global count global card_num # card_size: 牌的点数 card_num: 牌的张数 if card_size > 13: return if card_num == 13: count += 1 return if card_num > 13: return for i in range(5): # 每一类牌有0,1,2,3,4种方式 card_num += i dfs(card_size+1) card_num -= i num_conbinations()
标签:count,13,组合,python,dfs,num,card,size From: https://www.cnblogs.com/demo-deng/p/16618846.html