#include <stdio.h>
#include <string.h>
int C[101][101];
void init() {
memset(C, 0, sizeof (C));
}
int Cmn(int m, int n) {
if (m - n < n) {
return Cmn(m, m - n);
}
if (n == 0 || n == m) {
C[m][n] = 1;
return 1;
} else {
if (C[m - 1][n - 1] == 0) {
C[m - 1][n - 1] = Cmn(m - 1, n - 1);
}
if (C[m - 1][n] == 0) {
C[m - 1][n] = Cmn(m - 1, n);
}
return C[m - 1][n - 1] + C[m - 1][n];
}
}
int main() {
init();
printf("C(6, 0) = %d\n", Cmn(6, 0));
printf("C(6, 1) = %d\n", Cmn(6, 1));
printf("C(6, 2) = %d\n", Cmn(6, 2));
printf("C(6, 6) = %d\n", Cmn(6, 6));
return 0;
}
计算组合数
最新推荐文章于 2023-04-17 22:49:19 发布