comm.h

来自「Data Structures with C++附代码」· C头文件 代码 · 共 16 行

H
16
字号
// determine the number of committees with k members that
// can be chosen from n persons
int comm (int n, int k)
{
    // stopping condition; too few persons 
    if (k > n)    
        return 0;
    // stopping condition; committee of the whole or 0 members
    else if (n == k || k == 0)
        return 1;
    else
        // recursive step: all committes without person A
        // + all committees that include person A
        return comm(n-1,k) + comm(n-1,k-1);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?