Min-Max and the promotion and application of the inclusion-exclusion

concept

Min-Max capacity repellent, also called Inversion most, for a particular set, a maximum value at a known minimum of one case or the other of the seek algorithm.

E.g:

$$ max (a, b) = a + b-min (a, b) \\\ max (a, b, c) = a + b + c-min (a, b) -min (a, c) -min (b, c) + min (a, b, c) $$

Obviously, the number of all taking opposite number, easy to know the maximum value for the minimum of the formula with the same formula in the form of selecting the maximum value by the minimum value. The following discussion of the method of selecting the maximum value with only minimum.

form

Note $ Max (S) $ represents the maximum value of the set of $ S $, $ Min (S) $ $ S $ represents the minimum set, then:
$$
Max (S) = \ SUM \ limits_ {T \ Subset S, T \ NEQ \ Phi} (-. 1) ^ {| T |} -1 Min (T)
$$

Derivation

Provided there is a set size as arguments to a function satisfying $ f $ $ Max (S) = \ sum \ limits_ {T \ subset S, T \ neq \ phi} f (| T |) Min (T) $.

S $ $ note decreasing order of elements $ x_1, x_2, ..., x_m $, then for $ x_i $, its contribution to the left $ [i = 1] $, the contribution of the right side to $ \ sum \ limits_ {j = 0} ^ {i-1} {i-1 \ choose j} f (j + 1) $.

If the equation holds, it certainly has $ [i = 1] = \ sum \ limits_ {j = 0} ^ {i-1} {i-1 \ choose j} f (j + 1) $.

设 $F(i)=[i+1=1]$ (即 $[i=1]=F(i-1)$ ),$G(i)=f(i+1)$ ,则 $F(i)=\sum\limits_{j=0}^{i}{i\choose j}G(j)$ 。

For binomial inversion to give $ G (i) = \ sum \ limits_ {j = 0} ^ {i} (- 1) ^ {ij} {i \ choose j} F (j) = (- 1) ^ i $.

故 $f(i)=G(i-1)=(-1)^{i-1}$ 。

Thus configuration establishment, so that:
$$
Max (S) = \ SUM \ limits_ {T \ Subset S, T \ NEQ \ Phi} (-. 1) ^ {| T |} -1 Min (T)
$$

Another Proof

Consider equation right, referred to as the minimum $ $ x_i, then:

  • When $ i = 1 $, $ 1 to $ contribution;
  • When $ i \ neq 1 $, $ x_1 $ is selected from the group and has two options are not selected, and the coefficients of these two solutions correspond exactly opposite number, so the total contribution of $ 0 $.

Therefore, the right is the sum of $ x_1 = Max (S) $.

Spread

Note $ kMax (S) $ denotes the set of a large value of $ k $ $ $ S, then:
$$
Kmax (S) = \ SUM \ limits_ {T \ Subset S, | T | \ K} GE (-. 1) {^ | T | -k} {| T | -1 \} the Choose Min. 1-K (T)
$$

Derivation

Provided there is a set size as arguments to a function satisfies $ G $ $ kMax (S) = \ sum \ limits_ {T \ subset S, T \ neq \ phi} g (| T |) Min (T) $.

S $ $ note decreasing order of elements $ x_1, x_2, ..., x_m $, then for $ x_i $, its contribution to the left $ [i = k] $, the contribution of the right side to $ \ sum \ limits_ {j = 0} ^ {i-1} {i-1 \ choose j} g (j + 1) $.

If the equation holds, it certainly has $ [i = k] = \ sum \ limits_ {j = 0} ^ {i-1} {i-1 \ choose j} g (j + 1) $.

设 $F(i)=[i+1=k]$ (即 $[i=k]=F(i-1)$ ),$G(i)=g(i+1)$ ,则 $F(i)=\sum\limits_{j=0}^{i}{i\choose j}G(j)$ 。

For binomial inversion to give $ G (i) = \ sum \ limits_ {j = 0} ^ {i} (- 1) ^ {ij} {i \ choose j} F (j) = (- 1) ^ {i-k + 1} {i \ choose k-1} $.

故 $f(i)=G(i-1)=(-1)^{i-k}{i-1\choose k-1}$ 。

Thus configuration establishment, so that:
$$
Kmax (S) = \ SUM \ limits_ {T \ Subset S, | T | \ K} GE (-. 1) ^ {| T | -k} {| T | -1 \ the Choose } Min. 1-K (T)
$$

application

Min-Max and the promotion of inclusion and exclusion often used to resolve "all appear in the expected time" problem, approach:

Hutchison $ t_i $ indicating the occurrence time of the $ i $ th element, then:

  • $ Max (S) $ represents the maximum value of $ $ $ t $ S, i.e., the maximum time of all elements occurs, i.e., all elements appear time;
  • $ Min (S) $ S represents $ $ $ t $ the minimum, i.e., the minimum time of occurrence of all the elements, i.e. at least a time of occurrence.

The Min-Max-repellent capacity with $ Max (S) = \ sum \ limits_ {T \ subset S, T \ neq \ phi} (- 1) ^ {| T | -1} Min (T) $.

At the same time the left and right take a desired, due to the linear, a desired symbol can be directly summed into the inside, i.e., $ E (Max (S)) = \ sum \ limits_ {T \ subset S, T \ neq \ phi} (- 1) ^ {| T | -1} E (Min (T)) $.

Easy to find $ E (Min (T)) $ find it very easy: when $ T $ in at least a probability per unit time appear to $ p $, $ T $ in at least a desired time appears as $ \ frac 1p $ .

Can be determined by the equation Thus $ Max (S) $, i.e., the desired time of all of the elements appear.

For the same reason Min-kMax inclusion and exclusion.

Writing

If you ask them a $ Max (U) $, that is the maximum value of the complete works, then only need to calculate each his own contribution to the corpus.

If you want to request $ $ Max (S) $ of all $ S, then (although it seems not met), a faster method is to divide and conquer by bit instead of using a subset of the enumeration. There are two common writing, they can easily be processed into the form of equation.

Writing a

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

At this time, the coefficient is $ (- 1) ^ {| S | - | T} $.

Written two

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

At this time, the coefficient is $ (- 1) ^ {| T |} $.

example

[hdu4336]Card Collector

Subject to the effect

There are $ n $ types of cards, each purchase of $ p_i $ probability buy the first $ i $ species, so that each are seeking to buy the desired number of purchases.

$ 1 \ n \ le $ 20.

answer

Min-Max basis of inclusion and exclusion problems, see "Application" section above.

For this problem, there is $ Min (S) = \ frac 1 {\ sum \ limits_ {i \ in S} p_i} $, and then apply the formula $ Min-Max $ repellent capacity can be.

Time complexity $ O (2 ^ n) $.

#include <cstdio>
#define N 1100010
int cnt[N];
double p[N] , f[N];
int main()
{
    int n , i , j;
    double ans;
    while(~scanf("%d" , &n))
    {
        ans = 0;
        for(i = 0 ; i < n ; i ++ ) scanf("%lf" , &p[1 << i]);
        for(i = 1 ; i < (1 << n) ; i ++ ) f[i] = f[i - (i & (-i))] + p[i & (-i)] , cnt[i] = cnt[i - (i & -i)] + 1;
        for(i = 1 ; i < (1 << n) ; i ++ ) ans += ((cnt[i] & 1) ? 1 : -1) / f[i];
        printf("%lf\n" , ans);
    }
    return 0;
}

[Bzoj4036] bitwise OR

Subject to the effect

Your initial digital $ 0 $, each operation will randomly select $ [0,2 ^ n-1] $ is a number with your digital bitwise OR operation, the possibility of choosing the number of $ I $ $ p_i $. You find that becomes a desired frequency and digital $ 2 ^ n-1 $ operation.

$ 1 \ n \ le $ 20.

answer

The title and a similar problem is transformed to calculate $ Min (S) $, the need to obtain all of the elements with a common (and not taken $ 0 $) $ and $ S is the sum of $ p $.

N difficult the contrary, consider seeking all $ S $ no common element $ p $ sum, i.e., $ S $ complement of $ 2 ^ n-1-S $ all sub $ p $ of the set and, using press bit divide and conquer to solve.

Finally, you can set formula. Judgment no solution to deal with by determining whether there is a bit of a $ p \ neq 0 $ of elements.

Time complexity $ O (n \ times 2 ^ n) $.

Code

#include <cstdio>
#include <algorithm>
using namespace std;
double p[1100010];
int cnt[1100010];
int main()
{
    int n , i , j;
    double ans = 0;
    scanf("%d" , &n);
    for(i = 0 ; i < (1 << n) ; i ++ ) scanf("%lf" , &p[i]);
    for(i = 1 ; i < (1 << n) ; i ++ ) cnt[i] = cnt[i - (i & -i)] + 1;
    for(i = 1 ; i < (1 << n) ; i <<= 1)
    {
        for(j = 0 ; j < (1 << n) ; j ++ )
            if((j & i) && p[j])
                break;
        if(j == (1 << n))
        {
            puts("INF");
            return 0;
        }
    }
    for(i = 1 ; i < (1 << n) ; i <<= 1)
        for(j = 0 ; j < (1 << n) ; j ++ )
            if(j & i)
                p[j] += p[j ^ i];
    for(i = 1 ; i < (1 << n) ; i ++ ) ans += ((cnt[i] & 1) ? 1 : -1) / (1 - p[(1 << n) - 1 - i]);
    printf("%.8lf\n" , ans);
    return 0;
}

[Luogu4707] to return to this world

Subject to the effect

There $ $ n-substance per unit time will generate a random substance, generation probability of $ I $ substances is $ \ frac {p_i} m $. Seeking to obtain the desired time $ k $ substances.

$ 1 \ k \ 1000 $, $ 1 \ the m \ of 10,000 $, $ 1 \ k \ k $, $ p_i $ 为 整数 且 $ \ sum \ limits_ {at = 1} ^ np_i = m $, $ NK \ $ 10.

answer

Substances obtained $ k $, corresponds to the time required to obtain all of the first $ n-k + 1 $ large, Min-kMax transformed into the problem of inclusion and exclusion. Convenience, so $ q = n-k + 1 $, there is $ 1 \ le q \ le 11 $.

Due to a large $ n $ $ $ 1000, the subset of statistical methods two questions prior to use will obviously directly die-off.

Consideration: Although our set of selected program has $ 2 ^ n $ species, but each of $ Min (S) $ only and $ \ sum \ limits_ {i \ in S} p_i $, and therefore the number of states in fact only $ m $ species.

A comparison obvious idea is provided $ f_ {i, j, l} $ I $ $ represents the front $ J $ substances selected species, put together $ \ sum p = l $ program number, but the data is too large, You can not pass this question.

So far, we have not used one condition: $ q \ le 11 $.

Considered known $ f_ {i, j, l } $ calculated after answer, contribution $ (- 1) ^ {jq } {j-1 \ choose q-1} \ times \ frac ml \ times f_ {i , j, l} $. For the previous section, the use of a combination of the number of formulas have:
$$
(-1) ^ {} {J-JQ. 1 \ the Choose-Q. 1} = (-. 1) ^ {(. 1-J) - (. 1-Q) {2-J} \} the Choose Q-2 - (-. 1) ^ {(. 1-J) J-2 -q} {\ the Choose-Q. 1}
$$
and $ f_ {i, j, l } $ and metastasis $ f_ {i, j, l } = f_ {i-1, j, l} + f_ {i-1, j-1, l-p_i} $, so:
$$
(-1) ^ {JQ } {j-1 \ choose q -1} f_ {i, j, l} = (- 1) ^ {jq} {j-1 \ choose q-1} f_ {i-1, j, l} + ( -1) ^ {(j-1 ) - (q-1)} {j-2 \ choose q-2} f_ {i-1, j-1, l-p_i} - (- 1) ^ {(j -1)} {-q 2-J \ Q-the Choose F_ {}. 1. 1-I,. 1-J, L-P_i}
$$
found? Only the foregoing coefficients and J $ $ $ q and computation time used $ answer, and therefore provided $ g_ {i, j, l , t} $ I $ $ represents the front substances selected species $ J $, $ cobble \ sum p = l $, and finally $ q = t $ when calculating the coefficient multiplied by the number of programs. There:
$$
G_ {I, J, L, T} = {G_. 1-I, J, L, T} + {I-G_. 1,. 1-J, L-P_i, T--g_. 1} { . 1-I,. 1-J, L-P_i, T}
$$
We do seem to be wasted effort. But in fact, a closer look reveals $ j $ one-dimensional are no longer useful, whether it is transferred or not the final answer will need $ j $.

J $ $ about that dimension of sum, there $ h_ {i, l, t } $ I $ $ represents the front several substances selected, put together $ \ sum p = l $, and the final calculation of $ q = t $ coefficient multiplied by the number of programs, there are:
$$
H_ {I, L, T} = {H_-I. 1, L, T} + {H_-I. 1, L-P_i,. 1-T I--h_. 1 {}, L-P_i, T}
$$
final answer is $ \ sum \ limits_ {i = 1} ^ mh_ {n, i, q} \ times \ frac mi $.

Time complexity $ O (nmq) $, due to lack of space, we need to use the scroll array.

Code

#include <cstdio>
#include <cstring>
#define mod 998244353
typedef long long ll;
ll p[1010] , f[2][10010][11];
inline ll qpow(ll x , ll y)
{
    ll ans = 1;
    while(y)
    {
        if(y & 1) ans = ans * x % mod;
        x = x * x % mod , y >>= 1;
    }
    return ans;
}
int main()
{
    int n , t , m , i , j , k , d;
    ll ans = 0;
    scanf("%d%d%d" , &n , &t , &m) , t = n - t + 1;
    for(i = 1 ; i <= n ; i ++ ) scanf("%lld" , &p[i]);
    for(i = 1 ; i <= t ; i ++ ) f[0][0][i] = -1;
    for(d = i = 1 ; i <= n ; i ++ , d ^= 1)
    {
        memcpy(f[d] , f[d ^ 1] , sizeof(f[d]));
        for(j = p[i] ; j <= m ; j ++ )
            for(k = 1 ; k <= t ; k ++ )
                f[d][j][k] = (f[d][j][k] + f[d ^ 1][j - p[i]][k - 1] - f[d ^ 1][j - p[i]][k] + mod) % mod;
    }
    for(i = 1 ; i <= m ; i ++ ) ans = (ans + f[n & 1][i][t] * m % mod * qpow(i , mod - 2)) % mod;
    printf("%lld\n" , ans);
    return 0;
}

Guess you like

Origin www.cnblogs.com/GXZlegend/p/11563330.html