Luogu P4707 to return to this world (Min-Max to expand the inclusion and exclusion, DP)

Topic Link

https://www.luogu.org/problem/P4707

answer

Recently immortal question Eighth burst ......

First, Min-Max inclusion and exclusion certainly can think of, this problem is to use an extended version of the title --Kth Min-Max capacity denounced
this thing needs to have a deeper understanding of the nature of inclusion and exclusion Min-Max.
First we demonstrated Min-Max correctness of inclusion and exclusion from another angle: \ (\ max (S) = \ sum_ {T \ S} in F (| T |) \ min (T) \) , for the first \ ( (x + 1) \) a large number of times it has been calculated for the \ (\ sum_ {K \ 0} GE {X \ K} the Choose F (K +. 1) \) , there \ ([x = 0] = \ sum_ {K \ 0} GE {X \ K} the Choose F (K +. 1) \) , so that after inversion binomial \ (f (k) = ( - 1) ^ {k-1} \) to achieve their goals.
So just consider formulas \ ([x = 0] \ ) into \ ([x = k-1 ] \) will still take ideas how structure factor, the result is:? \ (F [the X- ] = (-. 1) ^ {} {XK-X. 1 \ K-the Choose. 1} \) .

The first problem corresponds to seeking \ (K \) large desired, can be converted into subsets Min: \ (\ text kthmax} {(S) = \ sum_ {T \ in S} (-. 1) ^ {| T | -K} {| T | -1 \ choose k-1} \ min (T) = \ sum_ {T \ in S} \ frac {m} {p_T} (- 1) ^ {| T | -K} {| T | -1 \ the Choose-K. 1} \) , where \ (p_T = \ sum_ {i
\ in T} p_i \) this may be a thing to carry out his dp: Let \ (dp [i] [j ] [K] \) representing the forward \ (I \) number \ (P \) sum of \ (J \) , when the number of metric \ (K \) when multiplied by each receiving program repellent coefficient with.
Transfer consideration: If the first \ (I \) element does not belong to \ (T \) , apparently plus \ (DP [. 1-I] [J] [K] \) ; if they are \ (T \) , then the number of combinations required \ ({| T | -1 \ the Choose-K. 1} = {| T | -2 \ the Choose-K +. 1 {} | T | -2 \ the Choose K-2} \) , for the previous direct entry is \ (DP [-I. 1] [P_i-J] [K] \) , for the latter as from \ (k-1 \)Transfer over, so to take more than a \ (--1 \) , the end result is minus \ ((dp [i-1 ] [j-p_i] [k] -dp [i-1] [j-p_i] [ 1-k]) \) .
However, this dp boundary problem difficult to handle. Then we might from the practical problems, to think about the number of combinations in the index is defined when the negative direct substitution available \ (dp [0] [0] [k] = - 1 (k> 0) \) .
(However, this feeling is not strict boundary setting method)

Time complexity \ (O (nm (NK)) \) .

Code

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>
#include<iostream>
#define llong long long
using namespace std;

inline int read()
{
    int x=0; bool f=1; char c=getchar();
    for(;!isdigit(c);c=getchar()) if(c=='-') f=0;
    for(; isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+(c^'0');
    if(f) return x;
    return -x;
}

const int N = 1000;
const int S = 1e4;
const int M = 11;
const int P = 998244353;
llong quickpow(llong x,llong y)
{
    llong cur = x,ret = 1ll;
    for(int i=0; y; i++)
    {
        if(y&(1ll<<i)) {y-=(1ll<<i); ret = ret*cur%P;}
        cur = cur*cur%P;
    }
    return ret;
}
llong mulinv(llong x) {return quickpow(x,P-2);}

llong a[N+3];
llong dp[S+3][M+2];
int n,m,s;

int main()
{
    scanf("%d%d%d",&n,&m,&s); m = n-m+1;
    for(int i=1; i<=n; i++) scanf("%lld",&a[i]);
    for(int i=1; i<=m; i++) dp[0][i] = P-1;
    for(int i=1; i<=n; i++)
    {
        for(int j=s; j>=a[i]; j--)
        {
            for(int k=1; k<=m; k++)
            {
                dp[j][k] = (dp[j][k]+dp[j-a[i]][k-1]-dp[j-a[i]][k]+P)%P;
            }
        }
    }
    llong ans = 0ll;
    for(int i=1; i<=s; i++)
    {
        ans = (ans+dp[i][m]*s%P*mulinv(i))%P;
    }
    printf("%lld\n",ans);
    return 0;
}

Guess you like

Origin www.cnblogs.com/suncongbo/p/11278273.html