Time Limit: 16 Seconds
Memory Limit: 16384 KB
Estelle Bright goes to Casino & Bar Lavantar to gamble. Among all the games, playing Poker is most possible to make much money (which is called Mira here), so Estelle decide to play this. But gambling has never been easy. Fortunately, with the help of Scherazard Harvey, she can know the queue of coming cards. However, this's not enough. So she still need bright Klose Rinz, the smart and beautiful princess, to help her to find the best strategy.
The rules of playing Poker are as follows:
- this game will use 4 * 13 = 52 kinds of cards, each infinity. At the beginning of each game, you should choose a bet in range 1 ~ 10 and you need to pay bet medals. You always begin with a rate 1
- each round, you will be given 5 cards first, then you can choose some (0 ~ 5) of them to hold and change the other ones, at last the 5 cards make up your hand
- after each round, according the category of your hand, the rate will multiply a different number. If your rate is 0, the game is over, or you can choose to continue playing or not. You will get bet * rate medals (1 Mira = 5 medals) at the end of the game
- a hand always consists of five cards, here are the categories of the hands:
||A no pair hand is a poker hand in which no two cards have the same rank, the five cards are not in sequence, and the five cards are not all the same suit.
||One pair is a poker hand which contains two cards of the same rank, plus three other unmatched cards.
||A poker hand such as which contains two cards of the same rank, plus two cards of another rank (that match each other but not the first pair), plus one unmatched card, is called two pair.
|Three of a kind
||Three of a kind is a poker hand which contains three cards of the same rank, plus two unmatched cards.
||A straight is a poker hand which contains five cards of sequential rank but in more than one suit. HA H2 H3 H4 D5 is not a straight.
||A flush is a poker hand which contains five cards of the same suit, not in rank sequence.
||A full house is a hand which contains three matching cards of one rank, and two matching cards of another rank.
|Four of a kind
||Four of a kind is a poker hand such which contains no less than four cards of one rank, and an unmatched card of another rank.
||A straight flush is a poker hand which contains five cards in sequence, all of the same suit.
||An ace-high straight flush such as HA HK HQ HJ HT is known as a royal flush
- the rate can be 9999 at most, if it's turning to a number larger than 9999, then it will turn to 9999
Assuming that Estelle has 16 medals initially, how much medals can she has with the help of Klose after playing Poker once? Scherazard might cannot predict enough number of cards, Klose will never make a strategy that need unknown cards!
Each case begins with a number 16 <= n <= 160 indicating the size of the cards queue predicted by Scherazard. Then n string whose length is exactly 2 indicating the cards in order. Cards will be represented in format "suit rank" where suit is one of 'H', 'S', 'D', 'C' and rank is one of '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A'.
Output the maximum number of medals in a separate line.
HA SA DA CA H2 HK HQ HJ HT C3 D3 DQ C7 H9 S3 D4 C6 H8 ST DQ CA H5 S3 D9 C7 HJ SK D8 C6 H4 C2 DT
Strategy of the sample:
bet = 10
get cards: HA SA DA CA H2; change cards: SA DA CA H2; get: HK HQ HJ HT
hand: HA HK HQ HJ HT; royal flush; rate * 500
get cards: C3 D3 DQ C7 H9; hold cards: C3 D3 *; change at leaset one card
hand: C3 D3 S3 *; three of a kind; rate * 4
The background comes from the famous RPG game the Legend of Heroes: Sora no Kiseki Second Chapter by Nihon Falcom Corporation.
Author: WU, Zejun
Source: ZOJ Monthly, October 2008