HDOJ 2032 递推求组合数

杭电100题,牛们请略过。

# include <stdio.h>



int cnk[31][31];



void prepare(void)

{

    int i, j;

    

    for (i = 1; i < 31; ++i) cnk[i][0] = cnk[i][i] = 1;

    for (i = 2; i < 31; ++i)

    for (j = 1; j < i;  ++j)

           cnk[i][j] = cnk[i-1][j-1] + cnk[i-1][j];

}



int main()

{

    int n, i, j;

    

    prepare();

    while (~scanf("%d", &n))

    {

        for (i = 0; i < n; ++i)

        {

            printf("1");

            for (j = 1; j <= i; ++j) printf(" %d", cnk[i][j]);

            putchar('\n');

        }

        putchar('\n');

    }



    return 0;

}

你可能感兴趣的:(组合)