# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|
19264 | | kriii | 악수 (kriii4_D) | C++14 | | 1238 ms | 6600 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
const long long mod = 1000000007;
long long inv[800],comb[800][800],end[41][800],all[41][800];
int main()
{
int n,m; scanf ("%d",&n);
comb[0][0] = comb[1][0] = comb[1][1] = inv[1] = 1;
for (int i=2;i<800;i++){
comb[i][0] = comb[i][i] = 1;
for (int j=1;j<i;j++) comb[i][j] = (comb[i-1][j-1] + comb[i-1][j]) % mod;
inv[i] = (mod - mod / i) * inv[mod % i] % mod;
}
end[1][0] = all[1][0] = 1;
for (int v=2;v<=n;v++){
int l = v * (v - 1) / 2;
for (int e=v-1;e<=l;e++){
for (int i=0;i<v-1;i++) for (int j=0;j<e;j++){
long long add = comb[v-1][i] * comb[e-1][j] % mod;
add = add * all[i+1][j] % mod;
add = add * all[v-i-1][e-j-1] % mod;
add = add * (i + 1) * (v - i - 1) % mod;
end[v][e] += add;
}
end[v][e] %= mod;
all[v][e] = (end[v][e] + (l - e + 1) * all[v][e-1]) % mod;
}
}
long long coeff = 1, ans = 0;
m = n * (n - 1) / 2;
for (int i=1;i<=m;i++){
coeff = coeff * inv[m-i+1] % mod;
ans = (ans + end[n][i] * coeff % mod * i) % mod;
}
printf ("%lld\n",ans);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |