http://acm.hdu.edu.cn/showproblem.php?pid=2519
唉,无聊了,刷水题~
求组合数~
#include <stdio.h>
#include <string.h>
#define MAXN 30
int c[MAXN + 5][MAXN + 5];
void init()
{
memset(c, 0, sizeof(c));
c[0][0] = 1;
for (int i = 0; i <= MAXN; i++) {
c[i][0] = c[i][i] = 1;
for (int j = 1; j < i; j++)
c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) ;
}
}
int main()
{
int t, m, n;
init();
scanf("%d", &t);
while (t--) {
scanf("%d%d", &n, &m);
if (m > n) {
printf("0\n");
} else
printf("%d\n", c[n][m]);
}
return 0;
}
本文介绍了一种使用C++来计算组合数的方法。通过预先计算并存储组合数,可以快速响应用户的输入请求,避免重复计算。文章提供了一个完整的C++程序示例。

363

被折叠的 条评论
为什么被折叠?



