Description
Input
The first line contains a number T,(T is about 100, including 90 small test cases and 10 large ones) denoting the number of the test cases. For each test cases,the first line contains two positive integers M and N(For large test cases,1<=M,N<=100, and for small ones 1<=M,N<=40). M denotes the row number and N denotes the column number. The next two lines each contains a string which contains only 'R' and 'D'. The length of string will not exceed 100. We ensure there are no empty strings and the two strings are different.
Output
For each test cases,print the answer MOD 1000000007 in one line.
Sample Input
2 3 2 RRD DDR 3 2 R D
Sample Output
1 10
思路:先构造一个AC自己主动机记录每一个状态包括两个串的状态,然后利用dp[i][j][k][s]表示i个R,j个D。此时AC自己主动机状态位置到k的时候,状态为s时的个数进行转移
#include#include #include #include #include using namespace std;const int mod = 1e9+7;int dp[110][110][220][4];int n,m;int nxt[420][2],fail[420],end[420];int root,cnt;inline int change(char ch) { if (ch == 'R') return 0; else return 1;}inline int newNode() { for (int i = 0; i < 2; i++) nxt[cnt][i] = -1; end[cnt++] = 0; return cnt-1;}inline void init() { cnt = 0; root = newNode();}inline void insert(char buf[], int id) { int len = strlen(buf); int now = root; for (int i = 0; i < len; i++) { if (nxt[now][change(buf[i])] == -1) nxt[now][change(buf[i])] = newNode(); now = nxt[now][change(buf[i])]; } end[now] |= (1<