아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Chains Solitaire

시간 제한1초메모리 제한512 MB

요약
52장의 카드를 7개 열로 나눠 받은 뒤, 같은 무늬 K부터 A까지 네 개의 열을 만드는 이동 순서를 찾거나 불가능을 판정한다.
난이도

보통10점 중 7점

유형
DFS, 시뮬레이션, 그리디, 구현
정답자
아직 제출이 없습니다

문제

In this problem a variation of <<Scorpion>> solitaire is presented.

You are given a deck of 5252 playing cards which are dealt into seven columns. Every column may have an arbitrary number of the cards, including cases when there are no cards in some columns (we call such columns empty). Each card has a suit (♢\diamondsuit, ♡\heartsuit, ♠\spadesuit, or ♣\clubsuit) and a rank (in increasing order: A, 22, 33, 44, 55, 66, 77, 88, 99, 1010, J, Q, K).

On each turn you are allowed to do the following: you choose the current card in some column (you may pick any) and move it onto the bottom card of another column together with all cards on top of it (a bottom part of column is moved as one unit). You are allowed to move the current card only onto a card of the same suit and rank larger exactly by 11. For example, 5♠5 \spadesuit can be moved only onto 6♠6 \spadesuit, and A♡\heartsuit can be moved only onto 2♡2 \heartsuit as it is shown in picture below. If the current card has rank K, you are allowed to move it only onto an empty column (together with all cards on top of it as well) and only if it lies on an another card (not on the top of a column).

The goal of the game is to build 44 columns of suit sequences from king to ace (K is in top of column, and A is in bottom).

입력

You are given 77 lines, the ii-th of which describes the ii-th column. The ii-th line starts with integer k_ik\_i --- the number of cards in the ii-th column (0≤k_i≤520 \le k\_i \le 52), followed by k_ik\_i two-symbol strings which describe cards in the ii-th column from top to bottom. The first symbol encodes a rank ("A", "2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q" and "K" for A, 22, 33, 44, 55, 66, 77, 88, 99, 1010, J, Q and K correspondingly), the second one encodes a suit ("D", "H", "S" and "C" for ♢\diamondsuit, ♡\heartsuit, ♠\spadesuit and ♣\clubsuit correspondingly). 

It is guaranteed that the input data contains all 5252 cards and that every of them occurs exactly once.

출력

If it is impossible to win the game, print "NO". Otherwise, in the first line print "YES", in the second line print the number of moves, and in the third line print cards in order of making turns. If there are several solutions, output any of them.

예제2

  1. 예제 1

    입력
    14 KD QD JD TD 9D 8D 7D 6D 5D 4D 3D 2D AD KH
    12 AS 6C 5C 4C 3C 2C AC 6S 5S 4S 3S 2S
    11 KS QS JS TS 9S 8S 7S 5H 4H 3H 2H
    1 KC
    0
    11 8H 7H 6H QC JC TC 9C 8C 7C QH JH
    3 AH TH 9H
    
    예상 출력
    YES
    10
    QH 6C AS KH AH QC 5H 6S TH 8H
    
  2. 예제 2

    입력
    5 JH TH 9H JC AH
    2 KH QH
    6 6H 2C AC KD 8H 7H
    6 QD JD 4H 3H KC QC
    10 3S 2S AS 8S 7S 6S 5S 4S QS JS
    12 3C TC 9C 8C 7C 6C 5C 4C KS TS 9S 2H
    11 TD 9D 8D 7D 6D 5D 4D 3D 2D AD 5H
    
    예상 출력
    YES
    20
    JH KD 6H KS JC 8H QD KC 2H TS QS 8S 3S AH TC 3C 2C 5H 4H TD