Description:
M m amino acids, known for their relative molecular mass of c1,c2,c3 ... C 1, C 2, c 3 ... C1,c2,c3., after a precise dehydration condensation, a large number of various peptide chains are formed. It is necessary to predict how many polypeptide chains have been hydrolyzed to the relative molecular mass and to n n N. (A−b−c (A−b−c (a-b-c and c−b−a c−b−a c-b-a two peptide chains as different)
Solution:
Consider having all the elements built into a generating function a (x) a (x) a (x), then the answer is ∑∞i=0a (x) i∑i = 0∞a (x) I \sum_{i=0}^{\infty}{a (x) ^i}
Answer according to the infinite Geometric series formula:
11−a (x) 1 1−a (x) \frac{1}{1-a (x)}
Polynomial inversion can be.
#include <cstdio> #include <cstring> #include <algorithm> using namespace std;
typedef long Long LL;
const int MAXN = 4e5 + 5, P = 1005060097;
int n, m, N, Len;
ll A[MAXN], B[MAXN], TMP[MAXN];
ll Power (ll X, ll T) {ll ret = 1;
for (; t; t >>= 1, x = x * x% P) {if (T & 1) {ret = ret * x% P;
}} return ret;
} void NTT (ll *a, int f) {for (int i = 0; i < N; ++i) {int t = 0; for (int j = 0; j < Len; ++j) {if (i >> J & 1) {T |= 1 << (len-j
-1);
}} if (I < T) {swap (A[i], a[t]);
}} for (int l = 2; l <= N; l <<= 1) {int m = l >> 1; ll w = Power (5, F = = 1?)
(P-1)/l:p-1-(P-1)/L); for (int i = 0; i < N; i + = L) {ll t = 1;
for (int k = 0; k < m; ++k, t = t * W% p) {ll x = A[i + K], y = t * a[i + M + K]% p;
A[i + K] = (x + y)% P;
A[i + M + K] = (x-y + p)% p;
}}} if (f = =-1) {LL inv = Power (N, P-2);
for (int i = 0; i < N; ++i) {a[i] = a[i] * INV% P;
}}} void Poly_inv (ll *a, ll *b, int l) {if (L = = 1) {b[0] = Power (a[0], P-2);
Return
} POLY_INV (A, B, l >> 1);
N = 1;
len = 0;
while (n <= l) {n <<= 1;
++len;
} for (int i = 0; i < L; ++i) {tmp[i] = A[i];
} for (int i = l; i < N; ++i) {tmp[i] = 0;
} NTT (TMP, 1);
NTT (b, 1); for (int i = 0; i < N; ++i) {B[i] = b[i] * (2-tmp[i] * B[i]% p + p)% p;
} NTT (b,-1);
for (int i = l; i < N; ++i) {b[i] = 0;
}} int main () {freopen ("polypeptide.in", "R", stdin);
Freopen ("Polypeptide.out", "w", stdout);
scanf ("%d%d", &n, &m);
++A[0];
for (int i = 1; I <= m; ++i) {int x;
scanf ("%d", &x);
--A[X];
} len = 1;
while (len <= N) {len <<= 1;
} POLY_INV (A, b, Len);
printf ("%lld\n", B[n]);
Fclose (stdin);
Fclose (stdout);
return 0; }