Interesting Words

시간 제한3초메모리 제한2048 MB

요약
주어진 단어를 중복 사용해 이어 붙여 길이가 정확히 L인 회문을 만드는 방법의 수를 1e9+7로 나눈 나머지로 구한다.
난이도

어려움10점 중 8점

유형
동적 계획법, 문자열, 트라이
정답자
아직 제출이 없습니다

문제

Ene loves palindromes.

Ene has a list of interesting words. She wants to select some interesting words and concatenate them to form a palindrome of length exactly LL. Each interesting word can be chosen multiple times or not chosen at all.

Ene wants to know the number of ways to do this. Two ways are considered different when the sequences of the concatenated interesting words in them are different. Note that multiple different ways may result in the same palindrome. Since the answer may be very large, you need to find the result modulo 109+710^9 + 7.

입력

The first line of the input contains two positive integers NN and LL representing the number of the interesting words and the length of the palindrome to be formed (1≤N≤3331 \le N \le 333, 1≤L≤10001 \le L \le 1000).

Each of the following NN lines contains an interesting word s_is\_i (1≤∣s_i∣≤L1\le |s\_i| \le L, ∑_i=1N∣s_i∣≤600\sum\_{i=1}^N |s\_i| \le 600; the interesting words only contain lowercase English letters and are pairwise distinct).

출력

Output a line with a single integer: the number of ways to form a palindrome modulo 109+710^9 + 7.

힌트

In the first example, the five different ways are the following:

stack cats; evil olive; eel eve lee; lee eve eel; eve eve eve.

예제3

  1. 예제 1

    입력
    7 9
    cats
    eel
    eve
    evil
    lee
    olive
    stack
    
    예상 출력
    5
    
  2. 예제 2

    입력
    2 2
    a
    aa
    
    예상 출력
    2
    
  3. 예제 3

    입력
    6 12
    aa
    aab
    no
    on
    pets
    step
    
    예상 출력
    43