# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
21636 |
2017-04-15T17:32:04 Z |
gs14004 |
악수 (kriii4_D) |
C++11 |
|
759 ms |
2288 KB |
#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 time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2288 KB |
Output is correct |
2 |
Correct |
0 ms |
2288 KB |
Output is correct |
3 |
Correct |
0 ms |
2288 KB |
Output is correct |
4 |
Correct |
0 ms |
2288 KB |
Output is correct |
5 |
Correct |
0 ms |
2288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2288 KB |
Output is correct |
2 |
Correct |
0 ms |
2288 KB |
Output is correct |
3 |
Correct |
0 ms |
2288 KB |
Output is correct |
4 |
Correct |
0 ms |
2288 KB |
Output is correct |
5 |
Correct |
0 ms |
2288 KB |
Output is correct |
6 |
Correct |
0 ms |
2288 KB |
Output is correct |
7 |
Correct |
3 ms |
2288 KB |
Output is correct |
8 |
Correct |
3 ms |
2288 KB |
Output is correct |
9 |
Correct |
6 ms |
2288 KB |
Output is correct |
10 |
Correct |
13 ms |
2288 KB |
Output is correct |
11 |
Correct |
16 ms |
2288 KB |
Output is correct |
12 |
Correct |
23 ms |
2288 KB |
Output is correct |
13 |
Correct |
33 ms |
2288 KB |
Output is correct |
14 |
Correct |
43 ms |
2288 KB |
Output is correct |
15 |
Correct |
63 ms |
2288 KB |
Output is correct |
16 |
Correct |
96 ms |
2288 KB |
Output is correct |
17 |
Correct |
106 ms |
2288 KB |
Output is correct |
18 |
Correct |
179 ms |
2288 KB |
Output is correct |
19 |
Correct |
203 ms |
2288 KB |
Output is correct |
20 |
Correct |
236 ms |
2288 KB |
Output is correct |
21 |
Correct |
333 ms |
2288 KB |
Output is correct |
22 |
Correct |
376 ms |
2288 KB |
Output is correct |
23 |
Correct |
526 ms |
2288 KB |
Output is correct |
24 |
Correct |
596 ms |
2288 KB |
Output is correct |
25 |
Correct |
759 ms |
2288 KB |
Output is correct |