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

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

Big Buttons

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

요약
길이 N인 R/B 문자열 중 주어진 P개의 금지 접두사로 시작하지 않는 문자열의 개수를 센다.
난이도

보통10점 중 5점

유형
트라이, 조합론, 정렬
정답자
아직 제출이 없습니다

문제

You are a contestant on a popular new game show and are playing for the grand prize!

There are two big buttons, a red one and a black one. You will make a sequence of exactly N button presses.

There are lots of different sequences of presses you could make, but there are P forbidden prefixes, each of length no greater than N. If you make a sequence of presses which begins with any of the forbidden sequences, you will not win the grand prize. It is fine for your sequence to contain one or more forbidden prefixes as long as they do not appear at the start of your sequence.

A winning sequence must consist of exactly N button presses and must not begin with one of the forbidden prefixes. How many different winning sequences are there?

입력

The first line of the input gives the number of test cases, T. T test cases follow. Each test case starts with a line containing two integers N and P, as described above. Then, there are P more lines, each of which contains a string of between 1 and N characters, inclusive, describing one of the forbidden sequences of presses. An R represents pressing the red button, whereas a B represents pressing the black button.

출력

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the number of winning sequences, as desribed above.

제한

  • 1 ≤ T ≤ 100.
  • 1 ≤ P ≤ min(2N, 100).
  • Each forbidden prefix is between 1 and N characters long, inclusive.
  • No two forbidden prefixes will be the same.

예제2

  1. 예제 1

    입력
    3
    3 2
    BBB
    RB
    5 1
    R
    4 3
    R
    B
    RBRB
    
    예상 출력
    Case #1: 5
    Case #2: 16
    Case #3: 0
    
  2. 예제 2

    입력
    1
    50 5
    BRBRBBBRBRRRBBB
    BRBRBRRRBRRRBRB
    BBBRBBBRBRRRBBB
    BRBRBRRRBRRRB
    BRBRBBBRBBBRB
    
    예상 출력
    Case #1: 1125556309458944