B3903 [NICA #3] 星空(Easy Version)
题目要求如下:
由于 不重复且为 ,则有:
考虑让最大值满足“相邻相加不大于 ”即可,设有 个数字满足,分类讨论如下:
- ,邻位有 种选择,剩余 位全排列;
- ,邻位分别有 种选择,剩余 位全排列;
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| #include<bits/stdc++.h> #define LL long long
using namespace std;
const int MAXN = 65; const LL mod = 1e9 + 7;
LL n, x; LL a[MAXN];
LL maxA, cnt; LL fac[MAXN];
int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
cin >> n >> x; fac[0] = 1; for (int i = 1; i <= n; ++i) fac[i] = (fac[i - 1] * i) % mod; for (int i = 1; i <= n; ++i) cin >> a[i]; maxA = *max_element(a + 1, a + n + 1); for (int i = 1; i <= n; ++i) if (a[i] != maxA && a[i] + maxA <= x) cnt++; LL ans1 = (2 * cnt * fac[n - 2]) % mod; LL ans2 = ((n - 2) * cnt * (cnt - 1) * fac[n - 3]) % mod; cout << (ans1 + ans2) % mod; return 0; }
|