답안 #19252

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
19252 2016-02-23T02:18:33 Z kaTkaHr 악수 (kriii4_D) C++14
5 / 100
715 ms 9020 KB
#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());
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1628 KB Output is correct
2 Correct 0 ms 1628 KB Output is correct
3 Correct 0 ms 1628 KB Output is correct
4 Correct 0 ms 1628 KB Output is correct
5 Correct 0 ms 1628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1628 KB Output is correct
2 Correct 0 ms 1628 KB Output is correct
3 Correct 0 ms 1628 KB Output is correct
4 Correct 0 ms 1628 KB Output is correct
5 Correct 0 ms 1628 KB Output is correct
6 Correct 0 ms 1628 KB Output is correct
7 Correct 0 ms 1628 KB Output is correct
8 Correct 4 ms 1760 KB Output is correct
9 Correct 7 ms 1760 KB Output is correct
10 Correct 12 ms 1892 KB Output is correct
11 Correct 20 ms 2024 KB Output is correct
12 Correct 33 ms 2288 KB Output is correct
13 Correct 50 ms 2684 KB Output is correct
14 Correct 81 ms 3080 KB Output is correct
15 Correct 134 ms 3740 KB Output is correct
16 Correct 207 ms 4532 KB Output is correct
17 Correct 317 ms 5588 KB Output is correct
18 Correct 468 ms 7040 KB Output is correct
19 Correct 715 ms 9020 KB Output is correct
20 Correct 0 ms 1628 KB Output is correct
21 Correct 0 ms 1628 KB Output is correct
22 Correct 0 ms 1628 KB Output is correct
23 Correct 0 ms 1628 KB Output is correct
24 Correct 0 ms 1628 KB Output is correct
25 Correct 0 ms 1628 KB Output is correct
26 Runtime error 0 ms 1624 KB SIGSEGV Segmentation fault
27 Halted 0 ms 0 KB -