[NOIP2025] 清仓甩卖 个人题解

· · 题解

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 998244353;
int t;
int n,m;
int a[200010];
int c[10010][10010];
ll p2[10010];

void init(){
    c[0][0]=1;
    for(int i=1;i<=10000;++i){
        c[i][0]=1;
    }
    for(int i=1;i<=10000;++i){
        for(int j=1;j<=i;++j){
            c[i][j]=c[i-1][j-1]+c[i-1][j];
            c[i][j]%=mod;
        }
    }
    p2[0]=1;
    for(int i=1;i<=5000;++i){
        p2[i]=p2[i-1]*2;
        p2[i]%=mod;
    }
    return;
}

bool cmp(int a,int b){
    return a>b;
}

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> t >> t;
    init();
    while(t-->0){
        cin >> n >> m;
        for(int i=1;i<=n;++i){
            cin >> a[i];
        }
        sort(a+1,a+n+1,cmp);
        ll ans=p2[n];
        for(int x=1;x<=n;++x){
            int lst=n+1;
            for(int y=x+1;y<=n;++y){
                if(a[x]==a[y] || m-x-1<0){
                    continue;
                }
                if(a[y]*2<=a[x]){
                    break;
                }
                while(a[lst-1]+a[y]<a[x] && lst>1){
                    --lst;
                }
                if(m-x-1>y-2){
                    continue;
                }
                ans-=c[y-2][m-x-1]%mod*p2[n-lst+1]%mod;
                ans%=mod;
                if(ans<0){
                    ans+=mod;
                }
            }
        }
        cout << ans << '\n';
    }
    return 0;
}

博客园链接