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

using namespace std;
long long dp[603][30];
long long kiedys[603][30];
string t[602];
int mod=1e9+7;
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    int n;
    cin>>n;
    int maxx=0;
    for(int i=1;i<=n;i++)
    {
        cin>>t[i];
        int ile=t[i].length();
        maxx=max(maxx,ile);
    }
    for(int x=1;x<=n;x++)
    {
        for(int j=0;j<=maxx;j++)
        {
            kiedys[j]['L'-'A']=0;
            kiedys[j]['P'-'A']=0;
        }
        string a=t[x];
        int ile=a.length();
        for(int i=0;i<a.length();i++)
        {
            if(a[i]=='L')
            {
                for(int j=ile;j>=1;j--)
                    kiedys[j]['L'-'A']=(kiedys[j-1]['L'-'A']+kiedys[j-1]['P'-'A'])%mod;
                kiedys[1]['L'-'A']++;
            }
            else{
                for(int j=0;j<=ile;j++)
                    kiedys[j]['P'-'A']=(kiedys[j+1]['L'-'A']+kiedys[j+1]['P'-'A'])%mod;
            }
        }
        for(int y=1;y<=n;y++)
        {
            for(int j=0;j<=maxx;j++)
            {
                dp[j]['L'-'A']=kiedys[j]['L'-'A'];
                dp[j]['P'-'A']=kiedys[j]['P'-'A'];
            }
            string a=t[x]+t[y];
            int ile=a.length();
            for(int i=t[x].length();i<a.length();i++)
            {
                if(a[i]=='L')
                {
                    for(int j=min(i,ile-i);j>=1;j--)
                        dp[j]['L'-'A']=(dp[j-1]['L'-'A']+dp[j-1]['P'-'A'])%mod;
                    dp[1]['L'-'A']++;
                }
                else{
                    for(int j=0;j<=min(i,ile-i);j++)
                        dp[j]['P'-'A']=(dp[j+1]['L'-'A']+dp[j+1]['P'-'A'])%mod;
                }
            }
            cout<<(dp[0]['L'-'A']+dp[0]['P'-'A'])%mod<<" ";
        }
        cout<<"\n";
    }
    return 0;
}