It's too weak to think of the wrong line formula.
First in the first m number to select the number of K-position unchanged, there is a C (M, k) scheme, and then enumerate the number of n-m in the following position of the numbers I, the remaining number of n-k-i is wrong row.
So here we're going to push a combination number and the number of rows.
By the way, review the wrong-row recurrence formula, Dn = (n-1) (Dn-1 + Dn-2), D0 = 1,D1 = 0.
Here I emphasize the value of the D0, I was just starting with a recursive result directly from D1 and D2 WA
1#include <cstdio>2typedefLong LongLL;3 4 Const intMAXN = ++Ten;5 ConstLL M =1000000007;6 LL C[MAXN][MAXN], D[MAXN];7 8inline ll Mul (ll A, ll b) {return(A * b)%M;}9 Ten voidInit () One { A for(inti =0; i < MAXN; i++) c[i][0] = C[i][i] =1; - for(inti =2; i < MAXN; i++) - for(intj =1; J < I; J + +) theC[I][J] = (c[i-1][J] + c[i-1][j-1]) %M; -d[0] =1; d[1] =0; d[2] =1; - for(inti =3; i < MAXN; i++) D[i] = Mul (i-1, (d[i-1] + d[i-2]) %M); - } + - intMain () + { A //freopen ("In.txt", "R", stdin); at - init (); - intT scanf"%d", &T); - for(intKase =1; Kase <= T; kase++) - { - intN, M, K; inscanf"%d%d%d", &n, &m, &k); -LL ans =0; to for(inti =0; I <= n-m; i++) +Ans = (ans + mul (c[n-m][i], d[n-k-i]))%M; -Ans = (ans * c[m][k])%M; theprintf"Case %d:%lld\n", Kase, ans); * } $ Panax Notoginseng return 0; -}code June
UVa 11481 (count) Arrange the Numbers