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
#include <iostream>
#include <vector>
#include <string>

using namespace std;

#define MAX_LEN 600
#define MOD 1000000007

void solve() {
    int n;
    cin >> n;

    vector<string> vec(n);
    for(int i = 0; i < n; i++) {
        cin >> vec[i];
    }

    vector<vector<int>> result(n, vector<int>(n, 0));

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            string cur_str = vec[i] + vec[j];
            vector<vector<int>> countL(cur_str.size()+1, vector<int>(cur_str.size()+1, 0));
            vector<vector<int>> countP(cur_str.size()+1, vector<int>(cur_str.size()+1, 0));
            int lastL = 0;
            int lastP = 0;
            
            if(cur_str[0] == 'L') {
                countL[1][1] = 1;
                lastL = 1;
            } 

            for(int k = 1; k < cur_str.size(); k++) {
                countL[k+1] = countL[k];
                countP[k+1] = countP[k];
                
                if(cur_str[k] == 'L') {
                    countL[k+1][1] += 1;
                    for(int q = 1; q < countL[k+1].size(); q++) {
                        countL[k+1][q] += (countL[k][q-1] + countP[k][q-1]) % MOD;
                        countL[k+1][q] %= MOD;
                    }
                    for(int q = 1; q < countL[k+1].size(); q++) {
                        countL[k+1][q] += MOD - countL[lastL][q];
                        countL[k+1][q] %= MOD;
                    }
                    lastL = k+1;
                } else {
                    for(int q = 0; q < countP[k+1].size()-1; q++) {
                        countP[k+1][q] += (countL[k][q+1] + countP[k][q+1]) % MOD;
                        countP[k+1][q] %= MOD;
                    }
                    for(int q = 0; q < countP[k+1].size()-1; q++) {
                        countP[k+1][q] += MOD - countP[lastP][q];
                        countP[k+1][q] %= MOD;
                    }
                    lastP = k+1;
                }
            }
            cout << (countL[countL.size()-1][0] + countP[countP.size()-1][0]) % MOD << " ";
        }
        cout << "\n";
    }
    
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    solve();

    return 0;
}