19 is Rui Summer Class B DAY3 combinatorics run again

Continued ...... reconnect dropped in ...... [fail: because too much food] ......

Inclusion-exclusion principle

Well actually it is a long variant of such a thing

\[\sum_{S \subseteq U} f(S) (-1)^{|S| + 1}\]

We then use it to calculate the Euler function formula

It is well known Euler function 1 ~ n is coprime with the number n

If \ (n = p_1 ^ {r_1 } * p_2 ^ {r_2} ...... * p_m ^ {r_m} \)

Then set up a wave of conversion, can be seen as the Euler function \ (n - | p_1 multiples of multiples \ cup p_2 of \ cup ...... \ cup p_m multiple of | \)

See this thing we feel very familiar, put it into

\(\sum_{T \in [n]} (-1)^T |\cap_{i \in T} S_i|\)

因为\(|\cap_{i \in T} S_i| = \frac{n}{\prod_{i \in T}p_i}\)

So the original formula $ = \ sum_ {T \ in [n]} (-1) ^ T \ frac {n} {\ prod_ {i \ in T} p_i} $

又因为\(\prod_{i = 1}^{n} (1 + x_i) = \sum_{S \in [n]}(\prod_{i \in S} x_i)\)

So the original formula \ (= \ sum_ {T \ in [n]} (-1) ^ T \ frac {n} {\ prod_ {i \ in T} p_i} \)

$ = n \sum_{T \in [n]} (-1)^T \frac{1}{\prod_{i \in T}p_i}$

$ = n\prod_{i = 1}^{m} (1 - \frac{1}{p_i})$


  • Known \ (x_1 + x_2 + ...... + x_n = A, 0 \ leq x_i \ leq C_i \)

    Solutions of how many groups there

If you ask \ (p \ leq x_i \) , then it is easier to forcibly remove enough p

Such as the requirement \ (1 \ leq x_1 \) other \ (x_i \) unlimited words

Is equivalent to the solution of all \ (x_i \) are unrestricted \ (x_1 + x_2 + ... + x_n = A - 1 \)

Then the solution was \ (x_1 \) plus a like

So here \ (0 \ leq x_i \ leq C_i \) the solution is

ans = Unlimited stops - limited only \ (C_1 \ leq x_1 \) stops - limited only \ (C_2 \ leq x_2 \) stops - limited only ....... + \ (C_1 \ leq x_1 \) and \ (C_2 \ leq x_2 \) stops only limit + \ (C_2 \ leq x_2 \) and \ (C_3 \ leq x_3 \) stops + .....

Such inclusion and exclusion go on the line


  • Sequence by a "<" and ">" is composed of 1 - has a bit length of n

    So you need to calculate p [i] <p [i + 1] if and only if s [i] is <the number of arrays of p

    n<=10^5

If this sequence, only "<" is very easy to handle just fine increments Well

Consider all the ">" set of permutations become unrestricted been clearly contain the original ">" arrangement in the case in

And this collection is arranged Rideau out the ">" into a legal arrangement "<" after

Then it can be the inclusion-exclusion

Consider several ">" into "<" legitimate number

Was turned into unlimited ">" "<" is divided into a number of consecutive put the native secondary "<" in the interval

??? Such as the sequence <<<<it is divided into A <B <C | D | E <F | G <H

Each section is increasing, the elements (such as the first section where A <B <C)

In this case it is arranged that the number of types \ (\ {n-FRAC!} {LEN_1! Len_2! ... len_k!} \) (K is divided into a number of sections)

ans = all ">" into an unlimited number of legitimate - a ">" to "<" Others ">" into an unlimited number of legitimate + 2 ">" to "<" Others ">" Variable to an unlimited number of legitimate .....

However \ (n \ leq 1e5 \) things get embarrassed

Consider each ">" into "<" after the contribution factor will become -1 "=" will contribute 1 (-1 is to make contributions to the so-called coefficient multiplied by -1)

Then push, you can find an interesting thing

\ (f [i] = \ sum f [j] \ frac {1} {(i - j)!} (-1) ^ {j + 1 -> i - 1 position between the ">" Number} \ ) (f [i] denotes the i th ">" before the answer is, as of the k-th section)

Finally, the answer is \ (n! F [k] \)

ps dls comes a very interesting thing

N 1 random arrangement relationship between the magnitude and the random number n (0, 1) of a real number is equivalent to the magnitude relationship


  • SetAndSet

    There are number of n, n <= 50, divided into two groups comes in handy to empty, and the number of each group all together. To make the results ⼀ kind. ⽐ as {1,2,3,4}, then {1,2}, {3,4} packet is legitimate, since 1 and 2 = 0, 3 and 4 = 0.

    Each number <= 2 ^ 20.

Complement conversion. Consider how can we not do the same? For a bit, the sequence can be seen as consisting of 0,1.

If you want to be different, then there is a division of at least one side, the other side of the all-zero

However, this good statistics disjoint-set + Search enumeration on it

For each case the result is \ (^ {2} communication block number - 2 \)


  • Min-Max inclusion and exclusion

\ (Max (x_1, x_2, x_3, ..., x_n) = x_1 + x_2 + ... + x_n - min (x_1, x_2) - min (x_2, x _3) ... \)

This thing often used in the calculation of the desired


  • Each birth ⽣ probability S is p (S), and the number of steps expected to ask corpus. | U | <= 20

A set of a desired number of steps is generated, the number of steps is desired that the last element is generated inside

那么\(E[max_{i = 1}^{n} x_i] = \sum_{T \subset [n],T \neq \emptyset}(-1)^{|T|}E[min_{i \in T}x_i]\)

And T is selected from the first element to the probability

T is the set of all or a subset of T intersects a probability of being selected

But the T disjoint sets very bad count

So turn it into a set of probabilities other than the above is not a choice

I.e. \ (1 - \ sum_ {S \ subset U \ T} P (S) \)

A desired number of steps is \ (\ frac {1} { 1 - \ sum_ {S \ subset U \ T} P (S)} \)

Add a set of prefix and the method of calculating

for(int i = 0; i < n; ++i)
    for(int S = 0; S <= (2 << n) - 1; ++S)
        if(S & (1 << i)) f[S] += f[S - (1 << i)];

  • A courseware n questions, each will be referred to again run probability p

    Seeking to speak through all the questions and then run the desired number of times

This question and on a very similar

\(ans = \sum_{i = 1}^{n} (-1)^{i} \tbinom{n}{i} \frac{1}{1 - (1 - p)^i}\)


  • "PKUWC2018" random walk

Surface link title

.. .. I expect to see traverse it rounding it is Min-Max

General idea is that the delivery points are introduced each went expectations + Min-Max inclusion-exclusion

Chicken dishesI am more interested in that part of recursive

(The following formula is recommended hand push, direct look easy to understand)

Happy when we have high extinction \ (f_u = 1+ \ frac { 1} {d_u} (\ sum_ {v \ in ch [d]} f_v + f_ {fa}) \)

Complexity \ (O (2 ^ nn ^ 3) \)

强行\(f_u = A_u f_{fa} + B_u\)

The transpose what has \ ((1 - \ frac { \ sum A_v} {d_u}) f_u = \ frac {1} {d_u} f_ {fa} + \ frac {1} {d_u} \ sum B_v + 1 \ )

Then we have leaves \ (f_v = f_ {fa} + 1 \) have A, B, and rooted f [root] = 0

Therefore wave A, B harvested from the bottom up, top to bottom and then harvested F [] thousand million

Complexity \ (O (2 ^ nn) \)

Guess you like

Origin www.cnblogs.com/hjmmm/p/11272141.html