Submission #21636

#TimeUsernameProblemLanguageResultExecution timeMemory
21636gs14004악수 (kriii4_D)C++11
100 / 100
759 ms2288 KiB
#include <bits/stdc++.h> using namespace std; typedef long long lint; typedef long double llf; typedef pair<int, int> pi; const int mod = 1e9 + 7; lint ipow(lint x, lint p){ lint ret = 1, piv = x % mod; while(p){ if(p&1) ret *= piv; piv *= piv; ret %= mod; piv %= mod; p >>= 1; } return ret % mod; } lint fact[805], invf[805]; lint dp[805][41]; lint bino(int x, int y){ return fact[x] * (invf[y] * invf[x-y] % mod) % mod; } int main(){ int n; cin >> n; fact[0] = invf[0] = 1; for(int i=1; i<=800; i++){ fact[i] = fact[i-1] * i % mod; invf[i] = ipow(fact[i], mod-2); } int s = bino(n, 2); dp[0][1] = 1; for(int i=1; i<=s; i++){ for(int j=1; j<=n; j++){ for(int k=0; k<i; k++){ for(int l=1; l<j; l++){ dp[i][j] += (dp[k][l] * dp[i-k-1][j-l] % mod) * ((l * (j - l) * bino(j, l) % mod) * bino(i-1, k) % mod); dp[i][j] %= mod; } } dp[i][j] *= ipow(2, mod-2); dp[i][j] += dp[i-1][j] * max(0ll, bino(j, 2) - (i - 1)); dp[i][j] %= mod; } } lint ans = 0; for(int i=1; i<=s; i++){ dp[i][n] *= invf[s] * fact[s-i] % mod; dp[i][n] %= mod; } for(int i=1; i<=s; i++){ lint cur = dp[i][n] - dp[i-1][n] + mod; cur *= i % mod; cur %= mod; ans += cur % mod; } ans %= mod; cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...