CodeForces-630 H. Benches【排列組合】

 Benches
time limit per test
0.5 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output

The city park of IT City contains n east to west paths and n north to south paths. Each east to west path crosses each north to south path, so there are n2 intersections.

The city funded purchase of five benches. To make it seems that there are many benches it was decided to place them on as many paths as possible. Obviously this requirement is satisfied by the following scheme: each bench is placed on a cross of paths and each path contains not more than one bench.

Help the park administration count the number of ways to place the benches.

Input

The only line of the input contains one integer n (5 ≤ n ≤ 100) — the number of east to west paths and north to south paths.

Output

Output one integer — the number of ways to place the benches.

Examples
input
5
output

120


題意:N*N的相交街道(可以當做棋盤),讓五個點放在上面:要求不同行也不同列!

需要對N個行進行排列(C(n,5)),再對N個列進行排列組合(A(n,5));

然後進行相乘:(C(n,5))*(A(n,5))!

ACcode

#include<stdio.h>
__int64 C(__int64 n,int m)
{
	int i;
	__int64 temp=1;
	for(i=1;i<=m;i++)
	temp=temp*(n-i+1)/i;
	return temp;
}
int main()
{
    __int64  n;
    while(scanf("%I64d",&n)!=EOF)
    {
    	printf("%I64d\n",120*C(n,5)*C(n,5));//c(n,5)*A(n,5)=c(n,5)*C(n,5)*A(5,5);
	}
	return  0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章