题解 P14149 振袖秋风问红叶
验题人题解。
其他题
A - 振袖秋风问红叶
upd:修复了 typo 及错误的代码,并在本题工单中提交了 hack。感谢@Rose_yy 提出该问题。
分析枫叶排列的定义,不难注意到如果从
:::success[代码]
const ll mod=998244353;
ll fac[1000010];
ll ksm(ll a,ll n){
if(n==0)return 1;
if(n==1)return a;
ll tmp=ksm(a,n/2);
return tmp*tmp%mod*(n&1?a:1)%mod;
}
int main(){
ios::sync_with_stdio(0);
ll T,a,b;
cin>>T;
fac[0]=1;
fac[1]=1;
for(int i=2;i<1000010;i++){
fac[i]=fac[i-1]*i%mod;
}
while(T--){
cin>>a>>b;
ll tmp=ksm(2,b-1);
if(b==a){
cout<<ksm(2,b-1)<<endl;
continue;
}
if(b<a){
tmp*=fac[a-b];
tmp%=mod;
tmp*=a-b-1;
tmp%=mod;
}
cout<<tmp<<endl;
}
return 0;
}
:::