/* O(2^n * n) 探索 */ #include #include #include #include #include #include #include #include using namespace std; void timer(){ static chrono::steady_clock::time_point start = chrono::steady_clock::now(); auto now = chrono::steady_clock::now(); cerr << "elapsed time : " << chrono::duration_cast(now-start).count() << "[ms]" << endl; } const long long mod = 1000000007; long long ans[20]; long long lcp[22][22]; vector s; int get_lcp_len(int x, int y){ if( lcp[x][y] != -1 ) return lcp[x][y]; string& a = s[x]; string& b = s[y]; for(int i=0; i0LL){ if(y&1LL) ret = (ret * x) % mod; x = (x*x) % mod; y >>= 1LL; } return ret; } long long fact[21]; int main(){ timer(); fact[0] = 1; for(int i=1; i<=20; i++){ fact[i] = fact[i-1] * i % mod; } for(int i=0; i<22; i++){ for(int j=0; j<22; j++){ lcp[i][j] = -1; } } int n; cin >> n; assert( n<=20 ); s = vector(n); for(int i=0; i> s[i]; s.push_back(string(1, 'a'-1)); s.push_back(string(1, 'z'+1)); sort(s.begin(), s.end()); for(int i=1; i<(1<>j)&1 ){ pre = j+1; continue; } int nxt = j+2; int len_a = get_lcp_len( j+1, pre ); int len_b = get_lcp_len( j+1, nxt ); tmp += max(len_a, len_b) + 1; } int k = __builtin_popcount(i); (ans[ k-1 ] += tmp ) %= mod; } for(int i=0; i