Xenny and Random Cubes
Practice
3.9 (57 votes)
Approved
Bit manipulation
Combinatorics
Easy
Math
Open
Ready
Problem
69% Success 3100 Attempts 30 Points 3s Time Limit 256MB Memory 1024 KB Max Code

Xenny had N cubes. Each cube had six faces and each face had a Latin character on each of it's sides. Xenny's friend Asdoc had an interesting activity in mind. He gave Xenny a string S and asked him to use the cubes to form that string. Xenny being a very lazy person, just wanted to randomly roll the cubes and then arrange a subset of them, to form the string S. Xenny relied on probability to get the desired string from the characters on the cubes.
Given the character on each face of each of the cubes, find out the the number of ways in which Xenny is able to make string S using the upward facing characters.

Input:

The first line of input consists of 2 space-separated integers - N and K - the number of cubes and the length of string S respectively.
N lines follow. Each line contains 6 space-separated characters, with ith line representing the characters on the 6 faces of the ith cube.
Last line of input contains string S.

Output:

Output the required number of ways MOD 109 + 7.

Constraints:

1 ≤ N ≤ 10
1 ≤ K ≤ N
S consists of lower-case Latin characters

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:30
32 votes
Tags:
ApprovedBit ManipulationDynamic ProgrammingEasyMatchingReady
Points:30
6 votes
Tags:
AlgorithmsApprovedBit ManipulationCircuitsDynamic ProgrammingEasyGame Theory
Points:30
21 votes
Tags:
AlgorithmsDynamic ProgrammingEasy