zoukankan      html  css  js  c++  java
  • CF1312D Count the Arrays

    题目链接:https://codeforces.com/contest/1312

    题目大意:

    想法:

    首先我们要在m个数里面取n-1个数即 C(m,n-1)

    然后取的这n-1个数里面最大的肯定是要在顶峰的位置,那么就要在n-2个数里面去找一个重复的数即 C(n-2,1)

    已知顶峰和重复的两个数我们就可以确定一个形式 x y x 然后对于剩下的n-3个数我们直接考虑放在y左边 和 y右边 两种情况就可以了即 2^(n-3)

    所以最后的答案   C(m,n-1)*C(n-2,1)*2^(n-3)

    #pragma GCC optimize(3,"Ofast","inline")//O3优化
    #pragma GCC optimize(2)//O2优化
    #include <algorithm>
    #include <string>
    #include <string.h>
    #include <vector>
    #include <map>
    #include <stack>
    #include <set>
    #include <queue>
    #include <math.h>
    #include <cstdio>
    #include <iomanip>
    #include <time.h>
    #include <bitset>
    #include <cmath>
    #include <sstream>
    #include <iostream>
    #include <cstring>
    
    #define LL long long
    #define ls nod<<1
    #define rs (nod<<1)+1
    #define pii pair<int,int>
    #define mp make_pair
    #define pb push_back
    #define INF 0x3f3f3f3f
    #define max(a,b) (a>b?a:b)
    #define min(a,b) (a<b?a:b)
    
    const double eps = 1e-10;
    const int maxn = 2e5 + 10;
    const LL mod = 998244353;
    
    int sgn(double a){return a < -eps ? -1 : a < eps ? 0 : 1;}
    using namespace std;
    
    LL da[maxn];//G++ long long
    void init()
    {
        int i;
        da[0]=1;
        da[1]=1;
        for(i=2;i<maxn;i++)
            da[i]=i*da[i-1]%mod;
    }
    LL quickmod(LL a,LL b)
    {
        LL ans=1;
        while(b)
        {
            if(b&1)
            {
                ans=(ans*a)%mod;
                b--;
            }
            b/=2;
            a=((a%mod)*(a%mod))%mod;
        }
        return ans;
    }
    LL C(LL a, LL b)
    {
        return (da[a]%mod)*(quickmod(da[b]*da[a-b]%mod,mod-2))%mod;
    }
    
    int main() {
        init();
        LL n,m;
        cin >> n >> m;
        if (n <= 2) {
            cout << 0 << endl;
            return 0;
        }
        cout << C(m,n-1)*C(n-2,1)%mod*quickmod(2,n-3)%mod << endl;
        return 0;
    }
  • 相关阅读:
    vmware磁盘空间扩展
    Winrar发现损坏的压缩文件头
    java ASM动态生成类
    使用ffmpeg将任意格式视频转MP4格式
    mongodb导入csv结构化数据
    Vmware黑屏解决方法
    mysql命令行导入结构化数据
    mysql导入慢解决方法
    CategoryPanelGroup动态生成节点
    delphi XE7 判断手机返回键
  • 原文地址:https://www.cnblogs.com/-Ackerman/p/12516732.html
Copyright © 2011-2022 走看看