Eddy's AC难题 HDU

来源:互联网 发布:淘宝店铺音乐怎么添加 编辑:程序博客网 时间:2024/06/05 16:36

 Eddy's AC难题

 HDU - 2200 
Eddy是个ACMer,他不仅喜欢做ACM题,而且对于Ranklist中每个人的ac数量也有一定的研究,他在无聊时经常在纸上把Ranklist上每个人的ac题目的数量摘录下来,然后从中选择一部分人(或者全部)按照ac的数量分成两组进行比较,他想使第一组中的最小ac数大于第二组中的最大ac数,但是这样的情况会有很多,聪明的你知道这样的情况有多少种吗? 

特别说明:为了问题的简化,我们这里假设摘录下的人数为n人,而且每个人ac的数量不会相等,最后结果在64位整数范围内. 
Input
输入包含多组数据,每组包含一个整数n,表示从Ranklist上摘录的总人数。 
Output
对于每个实例,输出符合要求的总的方案数,每个输出占一行。 
Sample Input
24
Sample Output
117
这个题考察如何写组合数
组合数函数模板
long long C(long long n,long long a){//求组合数的模板函数!!    long long sum = 1;    long long i;    for(i = 1; i <= a; i++){        sum = sum*(n-i+1)/i;    }    return sum;}

code:
#include <iostream>#include <cstdio>#include <cstring>using namespace std;long long C(long long n,long long a){//求组合数的模板函数!!    long long sum = 1;    long long i;    for(i = 1; i <= a; i++){        sum = sum*(n-i+1)/i;    }    return sum;}int main(){    long long n;    while(~scanf("%lld",&n)){        long long i;        long long sum = 0;        for(i = 2; i <= n; i++){            sum += (i-1)*C(n,i);//长度为i的序列中一定有i-1种情况,乘上长度为i的序列有多少个就得到了长度为i的情况下所以可能的情况        }        printf("%lld\n",sum);    }    return 0;}


原创粉丝点击