• 《AtCoder Regular Contest 134 C》


    首先题意不能搞错,就是如果盒子为空也是不合法的,所以就是说

    我们给每个不是1的球绑定一个1,然后剩下的保证每个盒子里至少1个球。

    绑定的这些可以随便排列可以存在盒子为空的情况数即可。

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    typedef pair<int,int> pii;
    const int N = 2e5 + 5;
    const int M = 1e7 + 5;
    const LL Mod = 998244353;
    #define rep(at,am,as) for(int at = am;at <= as;++at)
    #define INF 1e9
    #define dbg(ax) cout << "now this num is " << ax << endl;
    inline long long ADD(long long x,long long y) {
        if(x + y < 0) return ((x + y) % Mod + Mod) % Mod;
        return (x + y) % Mod;
    }
    inline long long MUL(long long x,long long y) {
        if(x * y < 0) return ((x * y) % Mod + Mod) % Mod;
        return x * y % Mod;
    }
    inline long long DEC(long long x,long long y) {
        if(x - y < 0) return (x - y + Mod) % Mod;
        return (x - y) % Mod;
    }
    
    int n,k,a[N];
    LL f[205];
    void init() {
        f[0] = 1;rep(i,1,204) f[i] = f[i - 1] * i % Mod;
    }
    LL quick_mi(LL a,LL b) {
        LL re = 1;
        while(b) {
            if(b & 1) re = re * a % Mod;
            a = a * a % Mod;
            b >>= 1;
        }
        return re;
    }
    LL C(LL n,LL m) {
        LL ans = 1;
        if(m == 0) return 1;
        rep(i,n - m + 1,n) ans = ans * i % Mod;
        ans = ans * quick_mi(f[m],Mod - 2) % Mod;
        return ans;
    }
    void solve() { 
        init();
        cin >> n >> k;
        LL sum = 0;
        rep(i,1,n) {
            cin >> a[i];
            if(i > 1) sum += a[i];
        }
        if(a[1] <= sum) printf("0\n");
        else {
            LL ans = C(a[1] - sum - 1,k - 1);
            rep(i,2,n) ans = MUL(ans,C(a[i] + k - 1,k - 1));
            printf("%lld\n",ans);
        }
    }       
    int main() {
        // int _;
        // for(scanf("%d",&_);_;_--) {
            solve();
        //}
       // system("pause");
        return 0;
    }
    View Code
  • 相关阅读:
    反射工具类
    序列化反序列化工具类
    开发SCM系统笔记001
    卸载Oracle
    log4j日志级别
    类加载器与methodinterceptor接口
    hibernate 查询、二级缓存、连接池
    Hibernate缓存、组件、继承映射
    Hibernate映射1
    Hibernate配置文件
  • 原文地址:https://www.cnblogs.com/zwjzwj/p/15858904.html
Copyright © 2020-2023  润新知