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.
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 one integer — the number of ways to place the benches.
5
120
题意:
求n行n列的棋盘,选出五个点,分别位于不同行不同列的所有可能情况
分别对行和列单独处理,很容易推出规律:C(n,5)*A(n,5)
当然 A(n,5)=120*C(n,5)..
#include<stdio.h>
typedef long long ll;
ll C(ll n,ll m)
{
if(m>n-m)
{
m=n-m;
}
ll ans=1;
for(ll i=0;i<m;++i)
{
ans=ans*(n-i)/(i+1);
}
return ans;
}
int main()
{
ll n;
while(~scanf("%lld",&n))
{
printf("%I64d\n",120*C(n,5)*C(n,5));
}
return 0;
}