Robot Game

아직 제출이 없습니다시간 제한10초메모리 제한1024 MB

문제

(note: actual in-contest limit was 3 seconds, a higher limit was picked here to allow more things to work)

There are mm (1m1000)(1 \le m \le 1000) robots and mm tapes. The ii-th robot (1im)(1 \le i \le m) works on tape ii. Each tape is divided into nn (1n32)(1 \le n \le 32) squares from left to right, and are numbered 0,1,,n10, 1, \dots, n-1. Each square has three possible states: (1) the square has number 0 (2) the square has number 1 (3) the square is empty.

At any point, a robot must stand in one of the squares of a tape. After setting the initial positions of the robots on the tapes, the ii-th robot will execute a predetermined sequence of operations S_iS\_i. The operations consist of characters R01*.

  • R means the robot will move one square right. If there are no squares to the right, the robot will explode.
  • 0 means if the square the robot is currently at is nonempty, the robot will change the number in the square to 0. Otherwise, the robot will not modify the current square.
  • 1 means if the square the robot is currently at is nonempty, the robot will change the number in the square to 1. Otherwise, the robot will not modify the current square.
  • * means if the square the robot is currently at is nonempty, the robot will change the number xx currently in the square into 1x1-x. Otherwise, the robot will not modify the current square.

The state of the ii-th tape may be represented by a string of length nn. Each character may be either 01 or - (an empty square) representing the state of the corresponding square. The initial state of the ii-th tape is called the input to robot iiX_iX\_i. The state of the tape after the operations is called the output of robot iiY_iY\_i. Notice if the robot explodes, the robot won't have any output.

It is easy to see if a square is empty, the robot will never modify the square, so robots have the following property: if on tape ii (which is the tape robot ii works on), all the squares are empty, then the robot will do nothing, and the output of the robot simply says all squares are empty.

Now given inputs X_iX\_i to the robots and initial target outputs Y_iY\_i, we want to find a position pp (0p<n)(0 \le p < n) such that all robots can use the pp-th square of the tape as the start position, finish all operations without exploding, and satisfy the condition that the ii-th robot has output Y_iY\_i.

To make the problem harder, we want to know the number of combinations of inputs and outputs that have a feasible solution. In other words, we are interested in how many ways we may set the inputs to the robots X_0,X_1,,X_m1X\_0, X\_1, \dots, X\_{m-1} and the target outputs Y_0,Y_1,,Y_m1Y\_0, Y\_1, \dots, Y\_{m-1} such that there exists at least one position pp (0p<n)(0 \le p < n) such that all robots can set the pp-th square of the tape as the start position, finish all operations without exploding, and the output of the ii-th robot is Y_iY\_i. Since the answer might be large, output the answer modulo 109+710^9 + 7. Two combinations are different if and only if there exists a robot such that its input or its output are different in the two combinations.

입력

The first line contains two integers n,mn,m denoting the number of squares on each tape and the number of tapes. In the following mm lines, the ii-th line contains a string S_iS\_i consisting of characters R 0 1 *, denoting the sequence of operations of robot ii.

출력

The output consists of only one integer denoting the answer modulo 109+710^9 + 7.

제한

For all test cases, 1n321 \le n \le 321m10001 \le m \le 10001S_i1001 \le |S\_i| \le 100.