0
点赞
收藏
分享

微信扫一扫

递归和暴力求组合数

水墨_青花 2022-03-12 阅读 88
private static long combine(int m, int n) { //递归调用
    if(n == 0) return 1;
    if(n == 1) return m;
    if(n > m/2) return combine(m, m - n);
    if(n > 1) return combine(m - 1, n) + combine(m - 1, n - 1);
    return -1;
} 
private static long combine(int a, int b) {
    long res = 1;
    for (int i = a,j = 1; j <= b; i--, j++) res = res * i / j;
}
举报

相关推荐

0 条评论