タイトル説明
カードのスタック、1と10の間の各カード
4枚のカードの方法があります:
シングルアウト1
2張Duizaiのうち
5ザン・シャンジー、など12345
など112233としてペアと3のうち、
数10には、各ブランドが、少なくとも、どのくらいの数がお願いしている1-10表し時間は出て再生することができます
思考
検索を剪定のメモリ+
def dfs(state):
if tuple(state) in memo:
return memo[tuple(state)]
if sum(state) == 0:
return 0
else:
res = float('inf')
for i in range(10):
# 出顺子
if i < 6 and state[i] > 0 and state[i + 1] > 0 and state[i + 2] > 0 and state[i + 3] > 0 and state[
i + 4] > 0:
state[i] -= 1
state[i + 1] -= 1
state[i + 2] -= 1
state[i + 3] -= 1
state[i + 4] -= 1
res = min(res, dfs(state) + 1)
state[i] += 1
state[i + 1] += 1
state[i + 2] += 1
state[i + 3] += 1
state[i + 4] += 1
memo[tuple(state)] = res
# 出三连对子
if i < 8 and state[i] > 1 and state[i + 1] > 1 and state[i + 2] > 1:
state[i] -= 2
state[i + 1] -= 2
state[i + 2] -= 2
res = min(res, dfs(state) + 1)
state[i] += 2
state[i + 1] += 2
state[i + 2] += 2
memo[tuple(state)] = res
# 出2张对子
if res == float('inf') and state[i] > 1:
state[i] -= 2
res = min(res, dfs(state) + 1)
state[i] += 2
memo[tuple(state)] = res
# 单出一张
if res == float('inf') and state[i] > 0:
state[i] -= 1
res = min(res, dfs(state)+1)
state[i] += 1
memo[tuple(state)] = res
return res
memo = {}
# state = list(map(int, input().split()))
state = [4,4,4,4,4,4,4,4,3,3]
print(dfs(state))