2174. Cow Solitaire

单点时限: 2.0 sec

内存限制: 256 MB

Late summer on the farm is a slow time, very slow. Betsy has little to do but play cow solitaire. For self-evident reasons, cow solitaire is not so challenging as any number of solitaire games played by humans.

Cow solitaire is played using an N x N (3 <= N <= 7) grid of ordinary playing cards with four suits (Clubs, Diamonds, Hearts, and Spaces) of 13 cards (Ace, 2, 3, 4, …, 10, Jack, Queen, King). Cards are named with two characters: their value (A, 2, 3, 4, …, 9, T, J, Q, K) followed by their suit (C, D, H, S). Below is a typical grid when N = 4:

     8S AD 3C AC     (Eight of Spades, Ace of Diamonds, etc.)

8C 4H QD QS

5D 9H KC 7H

TC QC AS 2D

To play this solitaire game, Betsy starts in the lower left corner (TC) and proceeds using exactly 2*N-2 moves of ‘right’ or ‘up’ to the upper right corner. Along the way, she accumulates points for each card (Ace is worth 1 point, 2 is worth 2 points, …, 9 is worth 9 points, T is worth 10 points, J is 11, Q is 12, and K is 13) she traverses. Her goal is to amass the highest score.

If Betsy’s path was TC-QC-AS-2C-7H-QS-AC, her score would be 10+12+1+2+7+12+1=45. Had she taken the left side then top (TC-5D-8C-8S-AD-3C-AC), her score would be 10+5+8+8+1+3+1=36, not as good as the other route. The best score for this grid is 69 points (TC-QC-9H-KC-QD-QS-AC => 10+12+9+13+12+12+1).Betsy wants to know the best score she can achieve. One of the geek cows once told her something about “working from the end back to the beginning,” but she didn’t understand what they meant.

输入格式

  • Line 1: A single integer: N

  • Lines 2..N+1: Line i+1 lists the cards on row i (row 1 is the top row) using N space-separated card names arranged in the obvious order.

输出格式

  • Line 1: A single line with an integer that is the best possible score Betsy can achieve.

样例

Input
4
8S AD 3C AC
8C 4H QD QS
5D 9H KC 7H
TC QC AS 2D
Output
69

10 人解决,21 人已尝试。

10 份提交通过,共有 38 份提交。

6.9 EMB 奖励。

创建: 17 年,4 月前.

修改: 7 年前.

最后提交: 3 年,10 月前.

来源: Elite 2007 US Open Competition

题目标签