• HDU 2519 新生晚会(组合问题)


    新生晚会

    题目链接

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 14936 Accepted Submission(s): 5148

    Problem Description
    开学了,杭电又迎来了好多新生。ACMer想为新生准备一个节目。来报名要表演节目的人很多,多达N个,但是只需要从这N个人中选M个就够了,一共有多少种选择方法?

    Input
    数据的第一行包括一个正整数T,接下来有T组数据,每组数据占一行。
    每组数据包含两个整数N(来报名的人数,1<=N<=30),M(节目需要的人数0<=M<=30)

    Output
    每组数据输出一个整数,每个输出占一行

    Sample Input
    5
    3 2
    5 3
    4 4
    3 6
    8 0
    
    
    Sample Output
    3
    10
    1
    0
    1
    
    
    Source
    ECJTU 2008 Autumn Contest
    

    题目不难,这要是这注意溢出问题,别除边乘。

    #include<iostream>
    #include<algorithm>
    #include<cstdio>
    #include<cstring>
    #include<queue>
    using namespace std;
    int main()
    {
        int t,n,m;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d %d",&n,&m);
            if(n<m)
                printf("0
    ");
            else if(n==m)
                printf("1
    ");
            else
            {
                long long int i,j,num=1;
                for(i=n,j=1;i>=(n-m+1);i--,j++)
                {
                    num=num*i/j;
                }
                printf("%lld
    ",num);
            }
        }
        return 0;
    }
    
  • 相关阅读:
    Android studio USB连接失败
    BZOJ 1013 [JSOI2008]球形空间产生器sphere
    UVA1025
    noip2016天天爱跑步
    noip2015运输计划
    noip2012借教室
    BZOJ 1597: [Usaco2008 Mar]土地购买
    BZOJ1010: [HNOI2008]玩具装箱toy
    BZOJ1026: [SCOI2009]windy数
    BZOJ1801:[Ahoi2009]chess 中国象棋
  • 原文地址:https://www.cnblogs.com/nanfenggu/p/7900006.html
Copyright © 2020-2023  润新知