zoukankan      html  css  js  c++  java
  • 牛客练习赛71 数学考试

    https://ac.nowcoder.com/acm/contest/7745/C

    真的第一次这么认真的考虑容斥定理,这个题我只相对了一半。

    假如他给了3个p  2 4 6,那就求出 只有 12开头的排列数量f[2],只有1234开头不包含12开头的f[4],只有123456开头不包含12和1234开头的排列数量f[6];

    动态规划的方法容斥,可以的。具体看代码把

    #include <iostream>
    #include <vector>
    #include <cstring>
    #include <cstdio>
    #include <algorithm>
    #include <set>
    using namespace std;
    typedef long long ll;
    int n,m;
    const int maxn = 2e5+11;
    ll list[maxn];
    ll mod = 20000311;
    ll ans[maxn];
    ll f[maxn];
    int main(){
        list[0] =1;
        for(int i=1;i<maxn;i++){
            list[i] = (list[i-1]*i)%mod;
        }
    
        cin>>n>>m;
        for(int i=0;i<m;i++){
            cin>>ans[i];
        }
        sort(ans,ans+m);
        for(int i=0;i<m;i++){
            f[i] = (list[ans[i]])%mod;
        }
        ll cns = list[n];
    
        for(int i=0;i<m;i++){
            for(int j=0;j<i;j++){
                f[i] = (f[i] - f[j]*list[ans[i] - ans[j]]%mod + mod)%mod;
            }
            cns = (cns - f[i]*list[n - ans[i]]%mod + mod)%mod;
        }
    
        cout<<cns<<endl;
        return 0;
    }
    

      

    寻找真正的热爱
  • 相关阅读:
    input.file上传图片| FileReader h5新特性
    lua的luasocket程序
    nginx的proxy_set_header
    lua的table.sort
    lua的深拷贝和浅拷贝
    nginx的location匹配
    kong后台接口
    一些程序和工具
    lua的模式匹配
    php的一些语法
  • 原文地址:https://www.cnblogs.com/lesning/p/13790040.html
Copyright © 2011-2022 走看看