permutation 2

permutation 2

Guess the conclusions made after a ==

$ N $ full permutation number, $ p_ {1} = x, p_ {2} = y $ claim $ | p_ {i + 1} -p_ {i} | <= 2 | $ arranged that satisfy the conditions required number.

First consider $ x =, y = case N $ 1, for any $ N $ has $ f (N) = f (N-1) + f (N-3) $ established, for $ x! = 0 $ of situation, regardless of the number before the first $ x $ are drained, for $ y! = N $ considering the number after the $ y $ drained, these numbers seem unique arrangement? ? ?

Then discharge is between $ x + 1 ~ y-1 $, similar row $ 1 ~ yx-1 $

#include<bits/stdc++.h>
using namespace std;
int T;
typedef long long ll;
ll A[100004];
ll mod=998244353;
void init()
{
    A[1]=1;
    A[2]=1;
    A[3]=1;
    for(int i=4;i<=100000;i++){
        A[i]=(A[i-1]+A[i-3])%mod;
    }
}
int main()
{
    init();
    scanf("%d",&T);
    ll a,b;
    ll N;
    while(T--){
        scanf("%lld%lld%lld",&N,&a,&b);
        if(a>b)swap(a,b);
        if(a!=1)
        a+=1;
        if(b!=N)
        b-=1;
        cout<<A[b-a+1]<<'\n';
    }


}

 

Guess you like

Origin www.cnblogs.com/liulex/p/11313886.html