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
87
88
89
90
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
const ll LINF = 1e18;
const int INF = 1e9;
const int MOD = 1e9 + 7;

pii dp[1201][1201];
pii dp2[1201][1201];

int mod(int x, int MOD) { return x >= MOD ? x - MOD : x; }

void clear(pii dp[1201][1201], int n) { 
    for (int i = 0; i <= n; ++i) {
        for (int j = i; j <= n; ++j) {
            dp[i][j].first = 0;
            dp[i][j].second = 0;
        }
    }
}

void copy_dp(pii dp[1201][1201], pii dp2[1201][1201], int n) { 
    for (int i = 0; i <= n; ++i) {
        for (int j = i; j <= n; ++j) {
            dp[i][j].first = dp2[i][j].first;
            dp[i][j].second = dp2[i][j].second;
        }
    }
}

int solve(const string &s, pii dp[1201][1201], int start_idx) {
    int n = start_idx + s.size();

    dp[0][0] = {0, 1};
    for (size_t str_i = 0; str_i < s.size(); ++str_i) {
        if (s[str_i] == 'L') {
            for (int j = n; j >= 1; --j) {
                for (int i = 0; i < j; ++i) {
                    dp[i][j].first = dp[i][j - 1].first + dp[i][j - 1].second;
                    dp[i][j].first = mod(dp[i][j].first, MOD);
                }
            }
        } else {
            for (int i = n; i >= 1; --i) {
                for (int j = i; j <= n; ++j) {
                    dp[i][j].second = dp[i - 1][j].first + dp[i - 1][j].second;
                    dp[i][j].second = mod(dp[i][j].second, MOD);
                }
            }
        }
    }

    int result = 0;
    for (int i = 1; i <= n; ++i) {
        result += dp[i][i].second;
        result = mod(result, MOD);
    }

    return result;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    vector<string> seqs(n);

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

    for (int i = 0; i < n; ++i) {
        clear(dp2, seqs[i].size() + 601);
        solve(seqs[i], dp2, 0);
        for (int j = 0; j < n; ++j) {
            copy_dp(dp, dp2, seqs[i].size() + seqs[j].size());
            cout << solve(seqs[j], dp, seqs[i].size()) << ' ';
        }
        cout << '\n';
    }

    return 0;
}