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
#include <string>
#include <iostream>
#include <set>
using namespace std;

const int MOD = 1000000007;
bool isIn(string fan, string s1, string s2){
    string s = s1+s2;
    int fLen = fan.length(), sLen=s.length(), pos=0;
    bool result=true;
    if (fLen>sLen) return false;
    for (int i=0; i < fLen; i++){
        pos = s.find(fan[i],pos)+1; 
        if((pos == 0) || (pos>sLen)){
            result=false;
            break;
        }
    }
    return result;
}


int main()
{
    int n;
    cin >> n;
    string drybl[n];
    set<string> fanStr[600];
    int fanArr[n][n];
    for (int i=0; i<n; i++){
        for (int j=0; j<n; j++){
            fanArr[i][j] = 0;
        }
    }
    int maxLen=0, dLen;
    for (int i=0; i<n; i++){
        cin >> drybl[i];
        dLen = drybl[i].length();
        if (dLen > maxLen) maxLen = dLen;
    }
    string newS;
    fanStr[0].insert("LP");
    for (int i=1; i<maxLen; i++){
        for(auto& shortStr: fanStr[i-1]){
            for (int j=0; j<=shortStr.length(); j++){
                newS=shortStr.substr(0,j)+"LP"+shortStr.substr(j,shortStr.length()-j);
                fanStr[i].insert(newS);
            }
        }
        
    }
    for(int k=0; k<maxLen; k++){
    for(auto& searchS: fanStr[k]){
        //cout << searchS<< endl;
        for (int i=0; i<n; i++){
            for (int j=0; j<n; j++){
                if (isIn(searchS,drybl[i],drybl[j])==true) {
                    fanArr[i][j]=(fanArr[i][j]+1) % MOD;
                }
            }
        }
    }
    }
    for (int i=0; i<n; i++){
        for (int j=0; j<n; j++){
            cout << fanArr[i][j] <<" ";
        }
        cout << endl;
    }

    return 0;
}