The first exam will become ⑨ baka
Get up feeling throat hurts, to the engine room directly GG, touched the armpit feeling pills.
Examination carried away, collapsing a bit much (
The order of examination questions set full of malice. . .
Problem A: 随
I saw the original root prompt on abandoned, wrote a \ (O (nmmod) \) violence, the results did not run through a point. . . .
First, this is a false expectation title, the total number of programs for the \ (the n-^ m \) , to obtain the sum of all the circumstances it
Set F [i] [j] is the value of the number of i x j operations, violent wave transfer. Write the equation can be found in the form of a matrix multiplication, this part is not to say, direct look positive solution, even after all these exams I did not write.
Task presenting us with original roots, we will use the original root. Can traverse the entire system in the remaining p-1 power by a power of primitive roots, we can replace the original power in the form of an array of a primitive root.
Thus, the original \ (a_i * a_j * a_k \ ) form becomes \ (G ^ G ^ I * J * K = G ^ G ^ {K} I + J + \) , multiplication becomes addition .
We changed the original look f, i represents the number of operations becomes j th original roots.
/*
______ ______
/ \ / \
| | | | | |
| | | | | |
| | | /\ | | |
\______/ \__/ \__/ \______/
*/
#include <bits/stdc++.h>
#define ll long long
const int MO = 1000000007, N = 100005;
int n, m, p, rt;
ll po[N], idx[N], a[N];
struct Matrix {
ll a[1005];
friend Matrix operator *(Matrix x, Matrix y) {
Matrix z = {};
for (int i = 0; i <= p - 1; i++)
for (int j = 0; j <= p - 1; j++)
z.a[(i + j) % (p - 1)] = (z.a[(i + j) % (p - 1)] + x.a[i] * y.a[j]) % MO;
return z;
}
inline void clear() {
for (int i = 0; i <= p - 1; i++) a[i] = 0;
}
Matrix qpow(int b) {
Matrix tmp, x = (*this);
tmp.clear(), tmp.a[idx[1]]++;
for (; b; b >>= 1, x = x * x)
if (b & 1) tmp = tmp * x;
return tmp;
}
} mtx, ans;
ll qpow(ll x, ll b, ll p) {
ll tmp = 1;
for (; b; b >>= 1, x = x * x % p)
if (b & 1) tmp = tmp * x % p;
return tmp;
}
inline int getrt(int x) {
for (int i = 2; i <= x; i++) {
ll tmp = 1; bool flg = 1;
for (int j = 1; j <= x - 2; j++) {
tmp = tmp * i % x;
if (tmp == 1) {
flg = 0;
break;
}
}
if (flg) return i;
}
}
signed main() {
scanf("%d%d%d", &n, &m, &p);
rt = getrt(p); po[0] = 1;
for (int i = 1; i <= p - 2; i++)
po[i] = po[i - 1] * (ll) rt % p, idx[po[i]] = i;
for (int i = 1; i <= n; i++)
scanf("%lld", &a[i]), mtx.a[idx[a[i]]]++;
ans = mtx.qpow(m);
ll tot = 0;
for (int i = 0; i <= p - 2; i++)
tot = (tot + po[i] * ans.a[i]) % MO;
ll inv = qpow(n, (ll) m * (MO - 2), MO);
printf("%lld\n", tot * inv % MO);
return 0;
}
Problem B: Single
Cluck
Problem C: title
T3 most do, wsl
Science open question sequence: C -> B -> A (
This thing tells us to put all the questions read, and who told you the title had to be ranked according to difficulty ascending (
There are problems in the pit, subtask 0,1,3 are white to 75 points, but I was stuck in the 2 3 have not been watching. . . .
Explained by the difficulty in ascending order, so unlike the topic al crumbs.
subtask 0:
Enumeration horizontally to the right the number of steps a, number of steps vertically upwardly c. The answer is \ (^ A C_ {n-C_n - A ^ A} n-C_ {-}. 2A = C ^ \ n-FRAC {!} {A A C C!!!!} \) .
Inverse pre-factorial factorial, bin
subtask 1:
Set right the number of steps a, left a few steps b, it is like the issue out of the stack, must remain a> = b. So the answer is Cat [n / 2].
subtask 3:
Subtask 0 and 1 is closed and the right number of steps enumerated level a, can calculate the number of steps up C, corresponding to the x-axis and y-axis side do subtask1.
The answer is \ (^ {C_n Cat. 2A} [A] Cat [C] \) .
subtask 2:
This combined count does not ask, I frantically try to inclusion and exclusion in the examination room, the result of capacity does not come out.
It is actually a very simple DP. Set f [i] for the i-th step back to the origin of the program number, back to the origin of the first enumerator step number j, which satisfies subtask 1. \ (F [I] = F [I - J] Cat [J / 2 -. 1] *. 4 \) .
Explain the details: Cat Why subscript to minus 1? Step inside j is not back to square one, the analogy can access the stack, we can not let the stack is empty. It is 4 × 4 directions.
After reading the question again open question! ! !
After reading the question again open question! ! !
/*
______ ______
/ \ / \
| | | | | |
| | | | | |
| | | /\ | | |
\______/ \__/ \__/ \______/
*/
#include <bits/stdc++.h>
#define ll long long
const int MO = 1000000007, N = 1000000 + 233;
int n, typ;
ll ans, fac[N], inv[N], cat[N];
ll Qpow(ll x, int b) {
ll ret = 1;
for (; b; b >>= 1, x = x * x % MO)
if (b & 1) ret = ret * x % MO;
return ret;
}
void init(int t) {
fac[0] = fac[1] = 1, cat[1] = 1, cat[0] = 1;
for (int i = 2; i <= t; i++) fac[i] = fac[i - 1] * i % MO;
for (int i = 0; i <= t; i++) inv[i] = Qpow(fac[i], MO - 2);
for (int i = 2; i <= t; i++) cat[i] = (cat[i - 1] * (4 * i - 2) % MO * Qpow(i + 1, MO - 2) % MO) % MO;
}
namespace case0 {
void QAQ() {
init(n);
for (int i = 0; i <= n; i += 2) {
int a = i / 2, c = (n - i) / 2;
ans = (ans + fac[n] * inv[a] % MO * inv[a] % MO * inv[c] % MO * inv[c] % MO) % MO;
}
printf("%lld\n", ans);
}
}
namespace case1 {
void QAQ() {
init(n);
printf("%lld\n", cat[n / 2]);
}
}
namespace case2 {
ll f[N];
void QAQ() {
init(n), n /= 2;
f[0] = 1, f[1] = 4;
for (int i = 2; i <= n; i++)
for (int j = 1; j <= i; j++)
f[i] = (f[i] + 4 * f[i - j] % MO * cat[j - 1]) % MO;
printf("%lld\n", f[n]% MO);
}
}
namespace case3 {
void QAQ() {
init(n);
for (int i = 0; i <= n; i += 2) {
int a = i / 2, c = (n - i) / 2;
ans = (ans + fac[n] * inv[i] % MO * inv[n - i] % MO * cat[a] % MO * cat[c] % MO) % MO;
}
printf("%lld\n", ans);
}
}
signed main() {
scanf("%d%d", &n, &typ);
if (typ == 0) case0::QAQ();
if (typ == 1) case1::QAQ();
if (typ == 2) case2::QAQ();
if (typ == 3) case3::QAQ();
return 0;
}