2020杭电多校第五场 hdu6825 Set1

题目链接

题目大意

有T组输入,对于每组输入一个 n(保证 n 是奇数),表示集合中有 1 到 n 的 n 个数,每次对集合删去集合中目前最小的数和随机一个数, 直到剩下最后一个数, 问每个数字被留到最后的概率。 输出对 998244353 取模。

1

暴力打表小数据然后找规律
在这里插入图片描述

在这里插入图片描述

code


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll mod=998244353;
const ll maxn=5e6+10;

ll fac[maxn];
ll invn[maxn];
ll invfac[maxn];

ll qpow(ll a, ll b) {
    ll ans = 1;
    while (b) {
        if (b & 1) ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}
int init(){
  int len=(int)(5e6+5);
  fac[0]=fac[1]=invfac[0]=invfac[1]=invn[0]=invn[1]=1;
  for(int i=2;i<=len;++i){
     fac[i]=fac[i-1]*i%mod;
     invn[i]=(mod-mod/i)*invn[mod%i]%mod;  //逆元线性递推公式
     invfac[i]=invfac[i-1]*invn[i]%mod;
  }
}

ll C(ll n,ll m){  // 组合数
    if(n>m) return 0;
    if(n<0 || m<0) return 0;
    ll res=fac[m];
    res=res*invfac[m-n]%mod;
    res=res*invfac[n]%mod;
    return res;
}

int main(){
 std::ios::sync_with_stdio(false);
 cin.tie(0); cout.tie(0); // 关同步
 init(); // 预处理阶乘和逆元
 int T;
 cin>>T;
 while(T--){
  int n;
  cin>>n;
  if(n==1) { ///特判
   cout<<1<<endl;
   continue;
  }
  for(int i=1;i<=n/2;++i){
   cout<<0<<" ";
  }
  for(ll i=n/2+1;i<=n;++i){
   cout<<C(n/2,i-1)*qpow(qpow(2,i-1),mod-2)%mod;
   if(i!=n) cout<<" ";
  }
  cout<<endl;
 }
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值