Benches(排列组合)

Benches(排列组合)
Time Limit:500MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

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.

Sample Input

Input
5
Output
120
题意:有n(5<=n<=100)条直线,n条横线,直线之间相互平行,横线之间相互平行,每条直线和每条横线都相交。即:n行n列。
现有5个椅子,把5把椅子,放在交点上,一个交点只能放一把椅子,且每一行最多只能有一把椅子,每一列最多只能有一把椅子。共有多少种方法。
思路:(1)从n条横线中选择5条放椅子,有n*(n-1)*(n-2)(n-3)(n-4)/(5!)种方法(2)从n条竖线中选择5条放椅子有n*(n-1)*(n-2)(n-3)(n-4)/(5!)种方法(3)经过前两部已经可以确定一个5*5的方阵,从这25个点中,选出5个点,且任意两点之间不同行不同列,有5!种方法。
sum=(1)*(2)*(3)

My  solution:

/*2016.3.11*/

#include<stdio.h>
int main()
{
	int i,n;
	long long ans;
	while(scanf("%d",&n)==1)
	{
		ans=1;
		for(i=n;i>=n-4;i--)
		ans*=i;
		ans=ans/120*ans;
		printf("%lld\n",ans);
	}
	return 0;
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值