Time limit
2s
Memory limit
128 MB
A unicorn is a chess piece similar to a knight. A knight moves two squares in one direction and one square in a perpendicular direction. A unicorn instead moves more than two squares in one of the four cardinal directions, then more than one square in one of the two perpendicular directions.
More precisely, one move is performed as follows.
The chessboard has size N×M. Each square contains one of the first L uppercase English letters.
Given N, M, L, and a word, count the number of unicorn paths whose occupied squares spell the given word in order. Print the count modulo 1,000,000,007.
The first line contains N, M, and L. Both N and M are positive integers no greater than 300, and L is a positive integer no greater than 26.
The second line contains the word. Its length is at most 50, and it consists only of uppercase English letters.
From the third line, N lines follow. Each of these lines is a string of length M describing the letters written on the chessboard.
Print the number of paths modulo 1,000,000,007 on the first line.