Two-entry inversion

Source: Internet
Author: User

Q: To give you k color, you must use all the colors to paint the n adjacent lattice, and require the adjacent lattice of different colors, to find the number of solutions.

We have to use the I color 22 of the non-adjacent coating lattice scheme number is B (i);

It is clear that we make a (k) =k ( K-1) n-1, then there.

If you know the two-item inversion , then the problem is solved, because.

Do you think the two-item inversion is very strong, I will give its proof below.

    • Two-term inversion formula:

      

    • Prove:

   

   

   Then let's do the analysis:

Let's warm up a bit:

There are a,b,c,d,e,f,g 7 people, we have to select 4 candidates from the first, and then choose 3 as Master.

      Then we can easily write down the number of its programs:

      but we think of it in another evil way :

         we can select 3 master internally and choose one from the remaining 4 people:.

      So it's easy to get this equation:

So there are

And then you'll see that the rest of the 1-1 is the n-j, so:

, so the primitive = B (n).

       so: established.

#include <bits/stdc++.h>using namespace Std;const int M = 1e6 + ten; int n, M, k; const int mod = 1e9 + 7; int key;        int f[m], inv[m], finv[m], void table () {inv[1] = 1;        for (int i = 2; i < M; i + +) inv[i] = (mod-mod/i) * 1ll * inv[mod%i]% mod;        F[0] = finv[0] = 1;                for (int i = 1; i < M; i + +) {F[i] = 1ll*f[i-1] * I% mod;        Finv[i] = 1ll*finv[i-1] * inv[i]% mod;        }}int Qkpow (int a, int b) {int ret = 1;                while (b) {if (b & 1) ret = 1ll*ret*a% mod;                b >>= 1;        A = 1ll*a*a%mod; } return ret;}        int comb (int n, int m) {if (M < 0 | | n < m) return 0; Return 1LL * f[n] * finv[m]% mod * finv[n-m]% MoD;} int solve (int x) {//cout << Qkpow ( -1, k-x) << "" << Comb (k,x) << "" << x <& Lt         "<< Qkpow (x-1, n-1) << Endl; Return 1LL*QKPow ( -1, k-x) * Comb (k, x) * x% mod * QKPOW (x-1, n-1)% MoD;}        int main () {int T;        Table ();        scanf ("%d", &t);                for (int cas = 1; CAs <= T; cas + +) {scanf ("%d%d%d", &n, &m, &k);                printf ("Case #%d:", CAs);                Key = 0;                        for (int i = 0; I <= k; i + +) {//puts ("heheh");                Key = ((1ll*key + 1ll*solve (i))% mod + MoD)% MoD;                }//puts ("======");                int ans = 1;                for (int i = 1; I <= K; i + +) {ans = 1ll*ans* (m-k+i)%mod;        } printf ("%d\n", key*1ll*ans%mod*finv[k]%mod); } return 0;}

Two-entry inversion

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.