Question
One of the famous Cards games in arabic countries called 14 played with 52 Cards Deck with 2, 3 or 4 Jokers. At the start
One of the famous Cards games in arabic countries called 14 played with 52 Cards Deck with 2, 3 or 4 Jokers.
At the start of the game, each player will have 14 cards. Each card has a certain value. The value of a number card is the number itself. The King, the Queen, the Jack and the Ace values are counted as the value of 10 . Each turn, a player must take a new card and throw a useless card. The player might choose to reveal a set of cards from his hand. To reveal a set, :
- The sum of values of the set must be >=51.
- The set consist of subsets. Each subset size is at least 3 cards and at most 5 cards.
- A subset must assembled of a successive cards from the same color, or different color cards of the same value.
- The Ace can be placed before the 2 and 3 or after the Queen and the King.
Your task is simple. Given a set of 15 cards, what is the maximum set sum the can be assembled ?
Input Format
An integer T represent the number of test cases, then T test case follow.
Each test case consist of two lines described as follows:
-
The First line will contain 15 separated characters. 2 - 10 for the numbers cards , A for the Ace , K for the King, Q for the Queen and J for the Jack.
-
The Second line will contain 15 separated characters of the set {c,d,h,s} for Clubs, Diamonds, Hearts and Spades, respectively.
Constraints
No joker will be added
Output Format
For each test case print the value of the maximum set sum can be assmbled. If the sum is print .
Sample Input 0
1 3 4 3 4 5 9 A J 2 7 Q 2 K 10 8 c c d s h d d h c d h d h d d
Sample Output 0
88
Explanation 0
The subset are as follows:
- {Kh,Qh,Jh} = 30
- {Ad,2d,3d} = 15
- {10d,9d,8d,7d} = 34
- {2c,3c,4c} = 9
Hence the sum is 88
using c++ or python3 or any language you prefer
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started