CF1312D Count the Arrays

Topic links: https://codeforces.com/contest/1312

 

Subject to the effect:

 

 

idea:

First, we have to take the number of n-1 in which the number m that is C (m, n-1)

This n-1 then the maximum number of which is certainly to be taking the position of the peak, then we would find a number of repeating inside i.e., C n-2 number (n-2,1)

And the peak number of repetition of two known we can determine a form xyx then for the remaining n-3 on the number y we consider directly the left and the right y both cases it i.e. 2 ^ (n-3)

 

Therefore, the final answer 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;
}

 

Guess you like

Origin www.cnblogs.com/-Ackerman/p/12516732.html