Project Euler Problem 53: Combinatoric selections【组合数】

PE其他解题报告请参考这里,本题答案在留言首条

Combinatoric selections

Problem 53

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

123 , 124 , 125 , 134 , 135 , 145 , 234 , 235 , 245 , a n d 345 123, 124, 125, 134, 135, 145, 234, 235, 245, and 345 123,124,125,134,135,145,234,235,245,and345

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

In general,
n C r = n ! r ! n ! − r ! nC_r = \frac {n!r!}{n!−r!} nCr=n!r!n!r!,where r ≤ n, n! = n×(n−1)×…×3×2×1, and 0! = 1.
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?


题意:

让你求组合数 C n m C_n^m Cnm 1 <= n <= 100, 1 <= m <= n,大于一百万的组合数的个数

分析:

根据组合数的性质,暴力跑就行,如果大于一百万,就赋值1000001,这样保证不会爆int

参考代码
#include<bits/stdc++.h>

using namespace std;

int c[111][111];

void init() {
    c[0][0] = 1;
    int cnt = 0;
    for (int i = 1; i <= 100; i++) {
        for (int j = 0; j <= i; j++) {
            if (j == 0 || j == i) c[i][j] = 1;
            else {
                int t = c[i - 1][j] + c[i - 1][j - 1];
                if (t > 1000000) c[i][j] = (int)(1e6) + 1, cnt++;
                else c[i][j] = t;
            }
        }
    }
    cout << cnt << endl;
}

int main(){
    init();
    return 0;
}```

***阅读好习惯:点赞 + 收藏~***






评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值