답안 #21635

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
21635 2017-04-15T17:28:31 Z gs14004 악수 (kriii4_D) C++11
0 / 100
0 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++){
		lint cur = dp[i][n] - dp[i-1][n] + mod;
		cur *= i * invf[s] % mod;
		cur %= mod;
		ans += cur % mod;
	}
	ans %= mod;
	cout << ans;
}
# 결과 실행 시간 메모리 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 Incorrect 0 ms 2288 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 2288 KB Output isn't correct
2 Halted 0 ms 0 KB -