/* O(n^2 |s|^2) dp */ #include #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[2000]; long long fact[2001]; long long nCr_[2001][2001]; long long mod_pow(long long x, long long y, long long mod){ //(x^y) % mod if(x==0 && y!=0) return 0; long long ret=1LL; while(y>0LL){ if(y&1LL) ret = (ret * x) % mod; x = (x*x) % mod; y >>= 1LL; } return ret; } long long nCr(long long n, long long r){ if(nCr_[n][r]) return nCr_[n][r]; return nCr_[n][r] = fact[n] * mod_pow(fact[r], mod-2, mod) % mod * mod_pow(fact[n-r], mod-2, mod) % mod; } struct trie_node{ map child; int count; }; vector trie; // dp[i][x] := i 頂点で合計長 x の組み合わせ vector> dfs(int pos, int d){ if( trie[pos].count == 1 ){ vector> dp(2); dp[0][0] = dp[1][1] = 1; return dp; } if( trie[pos].child.size() == 1 ){ return dfs(trie[pos].child.begin()->second, d+1); } vector> dp( trie[pos].count+1 ); dp[0][0] = 1; for(auto p : trie[pos].child){ if( p.first == '}' ) continue; vector> dp_( trie[pos].count+1 ); int nx = p.second; auto tmp = dfs(nx, 1); for(int i=0; i> dp_( trie[pos].count+1 ); dp_[0][0] = 1; for(int i=1; i<=trie[pos].count; i++){ for(auto p : dp[i]){ dp_[i][ p.first + d * min(trie[pos].count-1, i) ] = p.second; } } return dp_; } int main(){ timer(); fact[0] = 1; for(int i=1; i<=2000; i++){ fact[i] = fact[i-1] * i % mod; } int n; cin >> n; vector s(n); for(int i=0; i> s[i]; s[i] += '{'; } s.push_back("}"); trie.push_back( trie_node{{}, 0} ); for(int i=0; i