UVa 11481 (count) Arrange the Numbers

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.