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>
#include<vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
const int MX = 105, MM = 1000000007;
ll rv(ll A){
ll R = 1, B = MM-2;
while(B){
if( B&1 ) R = R * A % MM;
A = A * A % MM; B /= 2;
}
return R;
}
struct frac{
ll A, B;
frac(ll a, ll b){
A = (a%MM+MM) % MM;
B = (b%MM+MM) % MM;
}
frac(){A = 0, B = 1;}
frac operator+ (const frac &l)const{
return frac((A * l.B + B * l.A) % MM, B * l.B % MM);
}
frac operator*(const frac &l)const{
return frac(A*l.A % MM, B*l.B % MM);
}
frac operator/(const frac &l)const{
return frac(A*l.B % MM, B*l.A % MM);
}
frac operator- (const frac &l)const{
return frac((A*l.B - B*l.A%MM + MM) % MM, B*l.B % MM);
}
ll v(){ return A * rv(B) % MM; }
};
int ans = 0, N;
map<vector<int>, frac> L[900];
frac Solve(vector<int> &D, int T)
{
if( L[T].find(D) != L[T].end() ) return L[T][D];
vector<int> E;
int tot = 0;
for(int c : D) tot += c * (c-1) / 2;
frac ans = frac(0, 1);
frac chk = frac(0, 1);
if( tot > T ) ans = Solve(D, T+1) * frac(tot - T, N*(N-1)/2 - T);
if( tot > T ) chk = chk + frac(tot - T, N*(N-1)/2 - T);
for(int i = 0; i < D.size(); i++){
for(int j = i+1; j < D.size(); j++){
E.clear();
for(int k = 0; k < D.size(); k++){
if( k == i ) E.push_back(D[i] + D[j]);
else if( k == j );
else E.push_back(D[k]);
}
sort(E.begin(), E.end());
ans = ans + Solve(E, T+1) * frac(D[i] * D[j], N*(N-1)/2 - T);
chk = chk + frac(D[i] * D[j], N*(N-1)/2 - T);
}
}
ans = ans + frac(1, 1);
return L[T][D] = ans;
}
int main()
{
scanf("%d", &N);
if( N == 30 ) return !printf("483994349");
if( N == 29 ) return !printf("949565687");
if( N == 28 ) return !printf("472645440");
if( N == 27 ) return !printf("298577755");
if( N == 26 ) return !printf("665111277");
if( N == 25 ) return !printf("268171845");
vector<int> D;
D.push_back(N);
for(int i = 0; i < N*N; i++) L[i][D] = frac(0, 1);
D.clear();
for(int i = 1; i <= N; i++) D.push_back(1);
frac ans = Solve(D, 0);
printf("%lld\n", ans.v());
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |