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

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

Stacker

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

요약
일정 길이의 가로 블록을 테트리스처럼 위에서 떨어뜨려 목표 격자를 만들 수 있는지 판정하고, 가능하면 필요한 최소 블록 수를 구한다.
난이도

보통10점 중 6점

유형
백트래킹, 구현, 그리디
정답자
아직 제출이 없습니다

문제

The goal of this problem is simple: given a set of two-dimensional blocks, determine the least number of blocks necessary to construct them in a given configuration, if possible. All blocks have a width of 1, but the length will vary. The blocks themselves are stacked similar to Tetris, in that they are dropped from the top and will fall until any part of the falling block has collided with the ground or a preexisting block. The blocks may be selected in any order, moved left or right as needed, and they can be rotated.

You are limited to the number and lengths of blocks provided by the data. Not all configurations can be achieved with the given blocks.

입력

The first line of input will contain a single integer n that indicates the number of data sets to follow. Each data set will consist of:

  • A line containing two integers r and c, indicating the number of rows and columns, respectively, that the configuration will use. The value of rows and cols will both be between 1 and 50, inclusive.
  • The next r lines of c characters will be the configuration that you are trying to achieve, where a . (period) represents an open area and a # is a portion of a block.
  • The next line will contain a series of integers between 1 and 50 (inclusive), which represent the lengths of the blocks available for stacking.

출력

If it is possible to stack the available blocks in the given configurations, print the least number of blocks that could be used to accomplish this. If it is not possible, print “Not Possible.”

예제1

  1. 예제 1

    입력
    2
    5 5
    .....
    #####
    ...#.
    ...#.
    #..#.
    1 3 2 1 4
    7 7
    .......
    ....###
    .#...##
    .#...#.
    ###..#.
    ..#..#.
    ..#..#.
    1 2 2 2 2 3 3 4 5
    
    예상 출력
    Not Possible.
    6