题解:AT_aising2020_f Two Snuke

· · 题解

题意:

对于一个十元组 (a_1, a_2, b_1, b_2, c_1, c_2, d_1, d_2, e_1, e_2),我们定义合法的十元组需要满足:

现在,给定 n,你需要计算出所有合法的十元组的 (a_2 - a_1) \times (b_2 - b_1) \times (c_2 - c_1) \times (d_2 - d_1) \times (e_2 - e_1) 之和。

分析:

一道考验基本功的题。

为了将 < 这个条件消去,设

其中

很明显需要转化成小球放盒子的问题。

要求 \Delta a,\Delta b\dots\ge1,把 n 减掉 5(后文默认 n 都要减 5),该条件就变成了 \Delta a,\Delta b\dots\ge0。

所以我们完成了一个映射:有 n 个无标号的小球,16 个有标号的盒子。前 5 个盒子里的球的个数分别表示 A,B,C,D,E 的值。第 6 \sim15 个盒子的球的个数分别为 \Delta a,\Delta b\dots\ge1 掰成两份的值(求的是 \Delta a\Delta b\dots,这是个经典的组合意义)。第 16 个盒子的球的个数表示 n 没分完的(A+B+\dots+\Delta a+\Delta b\dots \le n)。注意每个盒子都可以为空。

最后一个问题,如何保证前 5 个盒子里球的个数均是偶数呢?直接枚举后面 11 个盒子有 i 个盒子是偶数。

那么对答案的贡献就是:

\binom{x+16-1}{15} \binom{11}{i}

其中 x= \frac{n-(11-i)}{2}。且 n-(11-i) 是偶数。

时间复杂度 O(T)。带点常数。

代码:
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
using namespace std;


namespace Fastio {
const int L = 1 << 20;
inline char gc() {
    static char buf[L], *l = buf, *r = buf;
    if (l == r)
        r = (l = buf) + fread(buf, 1, L, stdin);
    return (l == r) ? EOF : *l++;
}
char obuf[L], *p = obuf;
inline void pc(char c) {
    if (p == obuf + L)
        fwrite(obuf, 1, L, stdout), p = obuf;
    *p++ = c;
}
inline void flush() { fwrite(obuf, 1, p - obuf, stdout); }
struct Reader {
    template <typename T>
    inline Reader& operator>>(T& x) {
        x = 0;
        short f = 1;
        char c = gc();
        while (!isdigit(c)) {
            if (c == '-')
                f = -1;
            c = gc();
        }
        while (isdigit(c)) x = 10 * x + (c - '0'), c = gc();
        x *= f;
        return *this;
    }
    Reader() {}
} cin;
struct Writer {
    template <typename T>
    inline Writer& operator<<(T x) {
        if (x < 0)
            pc('-'), x = -x;
        static short tp = 0, s[40];
        do
            s[++tp] = x % 10, x /= 10;
        while (x);
        while (tp) pc(s[tp--] + '0');
        return *this;
    }
    inline Writer& operator<<(const char* s) {
        int i = 0;
        while (s[i]) pc(s[i++]);
        return *this;
    }
    inline Writer& operator<<(char c) {
        pc(c);
        return *this;
    }
    Writer() {}
    ~Writer() { flush(); }
} cout;
#define cin Fastio::cin


#define cout Fastio::cout


}


int T, n, ans;

int Pow(int a, int n) {
    if(n == 0) return 1;
    if(n == 1) return a;
    int x = Pow(a, n / 2);
    if(n % 2 == 0) return x * x % mod;
    else return x * x % mod * a % mod;
}

int inv(int x) {
    return Pow((x + mod) % mod, mod - 2);
}

int cc[20], Inv[20];

int C(int n, int m) {
    if(n < 0 || m < 0 || n < m) return 0;
    int res = 1;
    for(int i = n; i >= n - m + 1; i--) res = res * i % mod;
    return res * Inv[m] % mod;
}

int CC(int n, int m) {
    if(n < 0 || m < 0 || n < m) return 0;
    int res = 1;
    for(int i = n; i >= n - m + 1; i--) res = res * i % mod;
    int t = 1;
    for(int i = 1; i <= m; i++) t = t * i % mod;
    return res * inv(t) % mod;
}

signed main() {

    for(int i = 0; i <= 15; i++) cc[i] = CC(11, i);
    Inv[0] = 1;
    for(int i = 1; i <= 15; i++) Inv[i] = Inv[i - 1] * i % mod;
    for(int i = 0; i <= 15; i++) Inv[i] = inv(Inv[i]);

    cin >> T;
    while(T--) {
        cin >> n; ans = 0;
        if(n < 5) {
            cout << 0 << "\n";
            continue;
        }
        n -= 5;
        for(int i = 0; i <= 11; i++) {
            if(n < (11 - i)) continue;
            int x = (n - (11 - i)) / 2;
            if((n - (11 - i)) % 2 == 1) continue;
            ans += CC(x + 16 - 1, 16 - 1) * cc[i] % mod;
            ans %= mod;
        }
        cout << ans << "\n";
    }

    return 0;
}