ABCD Strings
Practice
5 (4 votes)
Graph theory
Linear algebra
Hard
Matrix exponentiation
Algorithms
Recursion
Mathematics
Open
Approved
Problem
78% Success 326 Attempts 50 Points 5s Time Limit 256MB Memory 1024 KB Max Code

Please find the number of N-length strings that are made of only letters 'a, 'b', 'c' and 'd' and do not contain any of the restricted strings.

Since, the answer can be very large, please print it modulo 1000000007.

Input Format:

The first line of input file contains T, the number of test cases to follow.
The first line of each test case contains 2 space-separated integers N and K.
The next K lines each contain a string S, which represents a restricted string.

Output Format:

Output T lines, each containing answer to corresponding test case.

Constraints:

T ≤ 200
N ≤ 1015
K ≤ 50
|S| ≤ 3

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
32 votes
Tags:
ApprovedBasic ProgrammingEasyOpen
Points:50
2 votes
Tags:
Linear AlgebraHardApprovedMathematicsOpenMatrix Exponentiation
Points:50
1 votes
Tags:
Dynamic ProgrammingLinear AlgebraHardMatrix ExponentiationAlgorithmsMathematicsOpenApproved