跳到正文

题解

题解:AT_aising2020_f Two Snuke

小超手123约 8 分钟
原文
文章信息与版本

文章信息

发布
2025年1月2日
收录
2025年12月12日
更新
2026年11月4日
篇幅
约 8 分钟
获赞
3

版本

  1. v1当前

题意:

对于一个十元组 (a1,a2,b1,b2,c1,c2,d1,d2,e1,e2)(a_1, a_2, b_1, b_2, c_1, c_2, d_1, d_2, e_1, e_2),我们定义合法的十元组需要满足:

  • 0≤a1<a20 \leq a_1 < a_2
  • 0≤b1<b20 \leq b_1 < b_2
  • 0≤c1<c20 \leq c_1 < c_2
  • 0≤d1<d20 \leq d_1 < d_2
  • 0≤e1<e20 \leq e_1 < e_2
  • a1+a2+b1+b2+c1+c2+d1+d2+e1+e2≤na_1 + a_2 + b_1 + b_2 + c_1 + c_2 + d_1 + d_2 + e_1 + e_2 \leq n

现在,给定 nn,你需要计算出所有合法的十元组的 (a2−a1)×(b2−b1)×(c2−c1)×(d2−d1)×(e2−e1)(a_2 - a_1) \times (b_2 - b_1) \times (c_2 - c_1) \times (d_2 - d_1) \times (e_2 - e_1) 之和。

分析:

一道考验基本功的题。

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

  • Δa=a2−a1,Δb=b2−b1,Δc=c2−c1,Δd=d2−d1,Δe=e2−e1\Delta a=a_{2}-a_{1},\Delta b=b_{2}-b_{1},\Delta c =c_{2}-c_{1},\Delta d=d_{2}-d_{1},\Delta e=e_{2}-e_{1}

  • A=2a1,B=2b1,C=2c1,d=2d1,e=2e1A=2a_{1},B=2b_{1},C=2c_{1},d=2d_{1},e=2e_{1}

其中

  • Δa,Δb⋯≥1\Delta a,\Delta b\dots\ge1

  • A,B,⋯≥0A,B,\dots \ge 0 且全为偶数。

  • A+B+⋯+Δa+Δb⋯≤nA+B+\dots+\Delta a+\Delta b\dots \le n。

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

要求 Δa,Δb⋯≥1\Delta a,\Delta b\dots\ge1,把 nn 减掉 55(后文默认 nn 都要减 55),该条件就变成了 Δa,Δb⋯≥0\Delta a,\Delta b\dots\ge0。

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

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

那么对答案的贡献就是:

(x+16−115)(11i)\binom{x+16-1}{15} \binom{11}{i}

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

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

代码:

C++
#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;
}
原文
存档评论3 条抓取于