#include #include #include #define int long long using namespace std; int n; string s[20]; int pre[20][20]; //pre[i][j] = 文字列s[i], s[j]の共通prefixの長さ int dp[1 << 20]; //dp[i] = i…既に読んだ読み札の集合, dp[i]…そこまでの全読み方における疲労度の総和 int fact[20]; int getPreNum(string &s, string &t) { int n = min(s.length(), t.length()); for (int i = 0; i < n; i++) { if (s[i] != t[i]) { return i; } } return n; } int bitCount(int x) { int cnt = 0; while (x > 0) { cnt += (x & 1); x >>= 1; } return cnt; } signed main() { int i, j, k; cin >> n; for (i = 0; i < n; i++) cin >> s[i]; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { pre[i][j] = getPreNum(s[i], s[j]); } } fact[0] = 1; for (i = 1; i < n; i++) { fact[i] = fact[i - 1] * i; fact[i] %= 1000000007; } //遷移前 < 遷移後なので、値が小さい状態から調べればよい。 for (i = 0; i < (1 << n) - 1; i++) { for (j = 0; j < n; j++) { if ((i >> j) & 1) continue; //読み札jを読む int tired = 0; for (k = 0; k < n; k++) { if (k != j && ((i >> k) & 1) == 0) { tired = max(tired, pre[j][k]); } } tired++; //遷移コスト = tired * その状態に至る経路の個数(=bitCount(i)!) dp[i + (1 << j)] += dp[i] + tired * fact[bitCount(i)]; dp[i + (1 << j)] %= 1000000007; } } int ans[21] = {0}; for (i = 0; i < (1 << n); i++) { ans[bitCount(i)] += dp[i]; ans[bitCount(i)] %= 1000000007; } for (i = 1; i <= n; i++) { cout << ans[i] << endl; } return 0; }