There are exactly ten ways of selecting three from five, 12345:

123, 124, 125, 134, 135, 145, 234, 235, 245, and 345

In combinatorics, we use the notation, 5C3 = 10.

In general,

It is not until n = 23, that a value exceeds one-million: 23C10 = 1144066.

How many, not necessarily distinct, values of  nCr, for 1  n  100, are greater than one-million?

题目大意:

从五个数12345中选出三个数一共有十种方法:

123, 124, 125, 134, 135, 145, 234, 235, 245, and 345

在组合数学中我们用5C3 = 10来表示.

n = 23时产生第一个超过一百万的数: 23C10 = 1144066.

对于nCr,  1  n  100,有多少超过100万的值?包括重复的在内。

  1. //(Problem 53)Combinatoric selections
  2. // Completed on Fri, 14 Feb 2014, 07:20
  3. // Language: C11
  4. //
  5. // 版权所有(C)acutus (mail: acutus@126.com)
  6. // 博客地址:http://www.cnblogs.com/acutus/
  7. #include<stdio.h>
  8. #include<math.h>
  9.  
  10. long long combinatoric(int n, int r) //计算组合数的函数
  11. {
  12. int i;
  13. long long s = ;
  14. if(r > n / ) r = n - r;
  15. for(i = n; i >= n - r + ; i--) {
  16. s *= i;
  17. }
  18. for(i = ; i <= r; i++) {
  19. s /= i;
  20. }
  21. return s;
  22. }
  23.  
  24. int main()
  25. {
  26. int i, j, s;
  27. s = ;
  28. for(i = ; i <= ; i++) {
  29. j = ;
  30. while(combinatoric(i, j) < ) j++;
  31. if(i % ) {
  32. s += (i / - j + ) * ; //利用组合数的对称性,分奇偶两种情况
  33. } else {
  34. s += (i / - j) * + ;
  35. }
  36. }
  37. printf("%d\n", s);
  38. return ;
  39. }
Answer:
4075

(Problem 53)Combinatoric selections的更多相关文章

  1. (Problem 29)Distinct powers

    Consider all integer combinations ofabfor 2a5 and 2b5: 22=4, 23=8, 24=16, 25=32 32=9, 33=27, 34=81, ...

  2. (Problem 22)Names scores

    Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-tho ...

  3. (Problem 73)Counting fractions in a range

    Consider the fraction, n/d, where n and d are positive integers. If nd and HCF(n,d)=1, it is called ...

  4. (Problem 42)Coded triangle numbers

    The nth term of the sequence of triangle numbers is given by, tn = ½n(n+1); so the first ten triangl ...

  5. (Problem 41)Pandigital prime

    We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly o ...

  6. (Problem 70)Totient permutation

    Euler's Totient function, φ(n) [sometimes called the phi function], is used to determine the number ...

  7. (Problem 74)Digit factorial chains

    The number 145 is well known for the property that the sum of the factorial of its digits is equal t ...

  8. (Problem 46)Goldbach's other conjecture

    It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a ...

  9. (Problem 72)Counting fractions

    Consider the fraction, n/d, where n and d are positive integers. If nd and HCF(n,d)=1, it is called ...

随机推荐

  1. HDU 3123-GCC(递推)

    GCC Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Subm ...

  2. go-vim配置

    一.环境准备: 系统环境说明: [root@docker golang]# cat /etc/redhat-release CentOS Linux release (Core) [root@dock ...

  3. 由RGB到HSV颜色空间的理解

    1. RGB模型 2. HSV模型 3. 如何理解RGB与HSV的联系 4. HSV在图像处理中的应用 5. opencv中RGB-->HSV实现 在图像处理中,最常用的颜色空间是RGB模型,常 ...

  4. Android 程序申请权限小知识点

    在Google Play 应用商店,显示至少支持设备的数量时候会用到权限数量.其他地方用处不大. Android系统提供为程序提供了权限申请,即在manifest中使用uses-permission来 ...

  5. 个人收集资料整理-WebForm

    [2016-03-23 20:35:53] C#实现局域网文件传输    win7系统中桌面图标显示不正常问题

  6. Windows phone 8.1 MessageBox 变了哦!

    using Windows.UI.Popups; public async void MessageBoxShow(string content, string caption) { MessageD ...

  7. Delphi2010新发现-类的构造和析构函数功能

    Delphi2010发布了. 虽然凭着对Delphi的热爱第一时间就安装了,但是现在可能是年纪大了,对新事物缺乏兴趣了.一直都没有仔细研究. 今天有点时间试了一下新功能. 本来C#和Delphi.NE ...

  8. Azure Traffic Manager 现可与 Azure 网站集成!

     编辑人员注释:本文章由 WindowsAzure 网站团队高级专家级工程师 Jim Cheshire撰写. AzureTraffic Manager 已经推出有一段时间,这是一种跨多个区域管理网 ...

  9. Codeforces 703D Mishka and Interesting sum(树状数组+扫描线)

    [题目链接] http://codeforces.com/contest/703/problem/D [题目大意] 给出一个数列以及m个询问,每个询问要求求出[L,R]区间内出现次数为偶数的数的异或和 ...

  10. Uber司机手机终端问答篇

    手机客户端 Q:自带安卓手机可以使用吗? A:安卓终端已经推出,请在微信页面点左下菜单选取“下载司机端APP”查看! Q:对自带苹果手机的要求? A:4S型号及以上且未越狱:使用3G或4G网络 Q:客 ...