题意:
对于一个十元组 ,我们定义合法的十元组需要满足:
现在,给定 ,你需要计算出所有合法的十元组的 之和。
分析:
一道考验基本功的题。
为了将 这个条件消去,设
其中
-
-
且全为偶数。
-
。
很明显需要转化成小球放盒子的问题。
要求 ,把 减掉 (后文默认 都要减 ),该条件就变成了 。
所以我们完成了一个映射:有 个无标号的小球, 个有标号的盒子。前 个盒子里的球的个数分别表示 的值。第 个盒子的球的个数分别为 掰成两份的值(求的是 ,这是个经典的组合意义)。第 个盒子的球的个数表示 没分完的()。注意每个盒子都可以为空。
最后一个问题,如何保证前 个盒子里球的个数均是偶数呢?直接枚举后面 个盒子有 个盒子是偶数。
那么对答案的贡献就是:
其中 。且 是偶数。
时间复杂度 。带点常数。
代码:
#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;
}