Project Euler:Problem 53 Combinatoric selections
2015-07-01 22:08
337 查看
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?
123, 124, 125, 134, 135, 145, 234, 235, 245, and 345
In combinatorics, we use the notation, 5C3 = 10.
In general,
nCr = | n! r!(n−r)! | ,where r ≤ n, n! = n×(n−1)×...×3×2×1, and 0! = 1. |
How many, not necessarily distinct, values of nCr,
for 1 ≤ n ≤ 100, are greater than one-million?
#include <iostream> #include <string> using namespace std; int c[101][101]; int main() { memset(c, 0, sizeof(c)); for (int i = 1; i <= 100; i++) { c[0][i] = 1; c[1][i] = i; c[i][i] = 1; c[i - 1][i] = i; } int count = 0; for (int n = 2; n <= 100; n++) { for (int r = 2; r < n; r++) { c[r] = c[r][n - 1] + c[r - 1][n - 1]; if (c[r] >1000000) { c[r] = 1000001; count++; } } } cout << count << endl; system("pause"); return 0; }
相关文章推荐
- 简单的底部菜单 类似微信订阅号里面的底部菜单
- PAT Advanced 1093. Count PAT's (25) 同 PAT Basic 1040
- 学习空间数据挖掘的总结
- ReactNavtive框架教程(2)
- 双击事件
- 戴尔服务器impi 设置
- Android UI中像素相关的名词解释
- oracle SQL语句
- php统计数组元素个数
- Pascal's Triangle
- 在EF的code frist下写稳健的权限管理系统:开篇(一)
- 【学习】序列DP
- BZOJ4158 : [POI2007]Railway
- 调用有道词典查词
- CSDN第一个博客,也是人生的第一个,哈哈哈
- MyBatis数据持久化(十)与Spring4整合
- MyBatis数据持久化(十)与Spring4整合
- SpringMVC+Spring+Mybatis整合
- autoreleasePool
- bash array