zoukankan      html  css  js  c++  java
  • codeforces 630H (组合数学)

    H - Benches
    Time Limit:500MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
    Submit Status

    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条南北向的路,n条东西向的路,相交形成n*n的方格,交点处是路口,现在有5个凳子要往路口方,要求1、每条路上只能放一个凳子问总共有多少种方法

    #include<stdio.h>
    #include<string.h>
    #include<cstdio> 
    #include<string>
    #include<math.h>
    #include<algorithm>
    #define LL long long
    #define PI atan(1.0)*4
    #define DD double
    #define MAX 30000
    #define mod 100
    #define dian 1.000000011
    #define INF 0x3f3f3f
    using namespace std;
    LL C(LL n,LL m)
    {
    	LL ans=1;
    	int num=1;
    	while(m--)
    	{
    		ans*=(n-m);
    		ans/=num;
    		num++;
    	}
    	return ans;
    }
    int main()
    {
    	LL n,m,j,i,t;
    	LL sum;
    	while(scanf("%lld",&n)!=EOF)
    	{
    		if(n<=5)
    		{
    			sum=1;
    			for(i=1;i<=n;i++)
    			    sum*=i;
    			printf("%lld
    ",sum);
    			continue;
    		}
    	    sum=C(n,5)*n*(n-1)*(n-2)*(n-3)*(n-4);
    	    printf("%lld
    ",sum);
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    题解 POJ1149 Pigs
    题解 【网络流24题】运输问题
    题解 【网络流24题】太空飞行计划
    题解 【网络流24题】方格取数问题
    题解 密码锁
    题解 【重庆八中模拟赛】寻找代表元
    题解 [SHOI2010]最小生成树
    题解 【ZJOI2009】 假期的宿舍
    题解 [ZJOI2008]树的统计Count
    JSP页面中的pageEncoding和contentType两种属性(转)
  • 原文地址:https://www.cnblogs.com/tonghao/p/5267051.html
Copyright © 2011-2022 走看看