当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

2203:Patience

题目描述
Sasha enjoys playing patiences. Last days he played very interesting patience on a rectangular grid 14 * 4. The rules of this patience are very simple. He takes a standard 52-card deck (without jokers), extracts all aces and lays them in the first column of the grid. Cell (1, 1) contains ace of diamonds, (1, 2) -- ace of hearts, (1, 3) -- ace of clubs and (1, 4) contains ace of spades. Then Sasha shuffles the rest of the deck and lays all cards in a sequental order by row, leaving column 2 empty, so all the columns from 3 to 14 are covered by cards.
After having laid all cards in such a manner, he is allowed to make moves. The move is determined by selection of a free cell. This free cell is to be covered by the card defined by the contents of the left adjacent cell. The covering card must have the same suit and the next value (order of values is: Ace 2 3 4 5 6 7 8 9 10 Jack Queen King). For example, if the cell (6, 3) contains the Queen of Spades, and the cell (7, 3) is empty, selecting cell (7, 3) will move the King of Spades to (7, 3) (and leave empty the cell where the King of Spades was before the move). If the left neighbour of the free cell contains a King or is empty, the move selecting this free cell is disabled.
The goal is to make each row ordered (i.e. columns from 1 to 13 must contain cards from Ace to King, and the column 14 must be empty). If all free cells follow Kings or empty cells, and the cards are not ordered, Sasha is considered a loser (in the classic version of this patience, the rest of the deck may be shuffled two times again leaving ordered cards on their positions, but Sasha is very experienced and often wins without additional shuffling).
Now Sasha wants to know some things about this patience. Imagine the position where three suits are already ordered, and the remaining suit is ordered partially. It is known that there are less than n highest cards that are not ordered. So only n rightmost columns may contain unordered cards. For example, if n = 3, columns from 1 to 11 are ordered, and columns from 12 to 14 contain Queen, King and empty cell in an arbitrary order. Sasha wants to determine how many of such positions for a given n have a winning strategy. For example, if n = 3, there is only one position that does not allow him to win: . . . [King] [empty] [Queen]. All other positions have a winning strategy:
1. . . . [Queen] [King] [empty] is already a goal position
2. . . . [Queen] [empty] [King] allows to move King adjacent to the Queen.
3. . . . [empty] [Queen] [King] becomes previous position after moving the Queen after the Jack.
4. . . . [empty] [King] [Queen] becomes goal position by moving the Queen after the Jack.
5. . . . [King] [Queen] [empty] becomes position 3 after moving the King to the free cell.
So for n = 3 the answer is 5.
Write the program that will get the answer for an arbitrary n from 1 to 13.
输入解释
Input file consists of only one integer number n.
输出解释
Write to the output file the answer to the task -- the number of positions with less than n highest cards not ordered in the remaining suit that have a winning strategy.
输入样例
4
输出样例
14

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-2203

最后修改于 2020-10-29T06:26:32+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000 65536