1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <bits/stdc++.h>

#define mod 1000000007

typedef long long ll;

using namespace std;

int nextl[610];
int nextp[610];
int layer[610][610];
int sum[610];
string input[610];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    for(int q=0; q<n; q++)
    {
        cin>>input[q];
    }
    for(int k1=0; k1<n; k1++)
    {
        for(int k2=0; k2<n; k2++)
        {
            for(int i=0; i<600; i++)
            {
                for(int j=0; j<600; j++)
                    layer[i][j]=0;
                sum[i]=0;
            }
            string s=input[k1]+input[k2];
            int lastp=-1;
            int lastl=-1;
            for(int i=s.size()-1; i>=0; i--)
            {
                if(lastl!=-1)
                    nextl[i+1]=lastl+1;
                else
                    nextl[i+1]=-1;
                if(lastp!=-1)
                    nextp[i+1]=lastp+1;
                else
                    nextp[i+1]=-1;
                if(s[i]=='L')
                    lastl=i;
                else
                    lastp=i;
            }
            if(lastl!=-1)
                nextl[0]=lastl+1;
            else
                nextl[0]=-1;
            if(lastp!=-1)
                nextp[0]=lastp+1;
            else
                nextp[0]=-1;

            layer[0][0]=1;
            for(int i=0; i<=s.size(); i++)
            {
                if(nextl[i]!=-1)
                    for(int j=0; j<605; j++)
                    {
                        layer[nextl[i]][j+1]+=layer[i][j];
                        layer[nextp[i]][j-1]%=mod;
                        sum[j+1]+=layer[i][j];
                        sum[j+1]%=mod;
                    }
                if(nextp[i]!=-1)
                    for(int j=1; j<605; j++)
                    {
                        layer[nextp[i]][j-1]+=layer[i][j];
                        layer[nextp[i]][j-1]%=mod;
                        sum[j-1]+=layer[i][j];
                        sum[j-1]%=mod;
                    }
            }
            cout<<sum[0]<<" ";
        }
        cout<<"\n";
    }
}