F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Blackjack

Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 277    Accepted Submission(s): 24


Problem Description
You, as a great mathematician and a former member of Blackjack Team, are recently declared ¡°unwelcome person¡± by managers of local casinos. Extremely bored, you reminded of your life forming a team beating casinos at blackjack worldwide, and decided to help your friends in winning blackjack games.
Blackjack, also known as twenty-one, is a game frequently seen in casinos, played with one deck, or several decks of 52 cards. The version your friend plays is slightly different from what we used to see in usual casinos. In this version, the game is played between a player and a dealer with a deck of n cards, namely a1, a2, . . . , an, instead of regular decks of 52 cards in standard version. The ith card has the unique numeric value ai, which is important in following description of rules.
The game is played in several rounds as long as not less than k (k ¡Ý 10) cards left in the deck. Cards are dealt from a1 to an, while each card is dealt out at most once. In each round, the player is dealt one card, then the dealer, then the player, then dealer. They now have two cards in their hand respectively. Then the player would keep on taking a hit until he busts (total value of his hand exceeds 21 points) or he feels it¡¯s enough (total value of his hand exceeds 15 points) or he has taken 3 hits already. He immediately loses the round if he busts. If he has taken 3 hits without bust, making his hand consist of 5 cards, he wins the round, ending the round right away. Then the dealer will use the exactly same strategy as the player. Of course, the dealer loses the round immediately if he busts, wins the round at once if his hand consists of 5 cards, with the same rule applying. If after taking hits neither the player nor the dealer wins or loses, sums of points (described below) in their hands will be compared, and the person with larger one will win the round. In case of tie, neither wins or loses. Of course, this ends the current round.
In the casino your friend plays, there is a special rule: before the game starts, the player is required to cut the deck of card exactly once. By saying cut the deck we mean to change deck of cards from
a1, a2, . . . , an
to
ap, ap+1, . . . ; aq, a1, a2, . . . , ap-1, aq+1, . . . , an(1 < p ¡Ü q < n)
With your super power (in hacking) you now know the deck of cards to play. Now you want to instruct your friend to cut the cards by telling your friend p and q in a secret manner, in order to maximize number of rounds he wins.
 

Input
There are several test cases.
For each test case, the first line contains two integers, namely n (20 ¡Ü n ¡Ü 2000) and k (10 ¡Ü k ¡Ü n).
The following lines contain totally n characters separated by spaces or line breaks. Characters can be any of A,2,3,4,5,6,7,8,T,J,Q,K where A stands for numeric 1 and T,J,Q,K stands for numeric 10.
Input is terminated by EOF.
 

Output
For each test case, output one line ¡°Case X: Y¡± where X is the test case number (starting from 1) and Y is a number indicating the desired answer.
 

Sample Input
20 10 8 4 7 8 8 K 5 A Q Q A Q 6 4 J 6 9 5 3 9 40 10 3 J 7 7 2 T J 6 A 4 4 8 J T 6 A 6 2 K 9 6 5 7 J T 3 5 5 3 7 7 J 5 3 A 5 9 Q 6 7
 

Sample Output
Case 1: 3 Case 2: 6
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 19:42:48, Gzip enabled