Looking for combinations that are up to 15 in a hand card

I am writing a program that deals with cards and hands. The hand has 5 cards. I want to know what a good algorithm to solve, which combination of cards adds up to 15. Kings, Queens, Jacks, are considered 10 and Ace are considered one.

+3
source share
2 answers

This is very similar to the sums of the subset that I recently answered: Amount Algorithm

The only thing you need to do is keep track of which card was used to go from possible[i]to possible[i+n]. You can track them using the second array by calling it card_used, and then set card_used[i+n]the link / index of the map used to go from ito i+n. Then at the end you can get a list of cards used to get the amount of 15 (assuming that possible[15]is true), going back through the list card_used.

+1
source

1) take the hand 2) loop through the hand
2a) each iteration, add the cost of the car to the total amount. 2b), if you ever reach more than 15, you can exit this iteration

0
source

Source: https://habr.com/ru/post/1778534/


All Articles