排列组合递推公式以及代码
A(n, m) = A(n - 1, m - 1) + A(n - m, m) {n在下,m在上,下同}
UESTC 1721
static final int MOD = 1000000007;
static final int MAXN = 2005;
int A[][];
void solve() {
A = new int[MAXN][MAXN];
for (int i = 1; i < MAXN; i++) {
A[i][1] = A[i][i] = 1;
}
for (int i = 3; i < MAXN; i++) {
for (int j = 2; j < i; j++) {
A[i][j] = (A[i - 1][j - 1] + A[i - j][j]) % MOD;
}
}
}
C(n, m) = C(n - 1, m - 1) + C(n - 1, m)
HDU 2032
static final int MAXN = 35; int C[][]; void solve() { C = new int[MAXN][MAXN]; for (int i = 1; i < MAXN; i++) { C[i][1] = C[i][i] = 1; } for (int i = 3; i < MAXN; i++) { for (int j = 2; j < i; j++) { C[i][j] = C[i - 1][j - 1] + C[i - 1][j]; } } }
注意:组合排列数会很大,注意变量的范围(可求余)