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万的值?包括重复的在内。

//(Problem 53)Combinatoric selections
// Completed on Fri, 14 Feb 2014, 07:20
// Language: C11
//
// 版权所有(C)acutus (mail: acutus@126.com)
// 博客地址:http://www.cnblogs.com/acutus/
#include<stdio.h>
#include<math.h> long long combinatoric(int n, int r) //计算组合数的函数
{
int i;
long long s = ;
if(r > n / ) r = n - r;
for(i = n; i >= n - r + ; i--) {
s *= i;
}
for(i = ; i <= r; i++) {
s /= i;
}
return s;
} int main()
{
int i, j, s;
s = ;
for(i = ; i <= ; i++) {
j = ;
while(combinatoric(i, j) < ) j++;
if(i % ) {
s += (i / - j + ) * ; //利用组合数的对称性,分奇偶两种情况
} else {
s += (i / - j) * + ;
}
}
printf("%d\n", s);
return ;
}
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. Oracle基础(二)---操作命令

    接上篇博客介绍Oracle基本概要.以下将介绍数据库的操作指令. Sql*plus经常使用命令 连接命令 1. conn[ect] 使用方法 connusername/password@网路服务名[a ...

  2. CentOS 安装Node.js

    先安装gcc-c++编译环境和openssl yum install gcc-c++ openssl-devel 然后 下载包并解压 cd /usr/local/src wget http://nod ...

  3. SQL学习之分组数据Group by

    简介:"Group By"根据字面上的意思理解,就是根据"By"后面指定的规则对数据进行分组(分组就是将一个数据集按照"By"指定的规则分成 ...

  4. 网页播放音频、视频文件——基于web的html 5的音乐播放器(转载)

    文章转载自:开源中国社区 [http://www.oschina.net] 想通过手机客户端(支持 Android.iPhone 和 Windows Phone)访问开源中国:请点这里 HTML5 是 ...

  5. WCF契约之---服务契约 、数据契约、 消息契约

    本篇博文只是简单说下WCF中的契约的种类.作用以及一些简单的代码示例.在WCF中契约分为服务契约.数据契约和消息契约.下面对这几种契约进行简单的介绍. 服务契约 服务契约描述了暴露给外部的类型(接口或 ...

  6. BZOJ 4000: [TJOI2015]棋盘( 状压dp + 矩阵快速幂 )

    状压dp, 然后转移都是一样的, 矩阵乘法+快速幂就行啦. O(logN*2^(3m)) ------------------------------------------------------- ...

  7. Enum基础

    enum ColorE {     RED, GREEN, BLUE; } public class GetEnumContent {     public static void main(Stri ...

  8. 高效的数组去重(js)

    function uniqueArray(data){ data = data || []; var a = {}; for (var i=0; i<data.length; i++) { va ...

  9. FZU Problem 1686 神龙的难题 重复覆盖

    题目链接 给出大矩形的长宽, 矩形里面有1,0两个值, 给出小矩形的长宽, 求用最少的小矩形覆盖所有的1. 重复覆盖的模板题. #include <iostream> #include & ...

  10. 记录.net 中的常见术语

    --Entity Framework和NHibernate --EF和NH都是一种ORM技术.就是对象关系模型映射. --NHibernate和Entity Framework 4.0优劣势争论 -- ...