Codeforces F - Serval and Bonus Problem

本文探讨了Beta函数的概念及其在复杂算法优化中的应用,通过解析代码实现,展示了如何利用Beta函数解决特定数学问题,重点讲解了算法背后的数学原理与编程技巧。

大佬链接
Beta函数是个什么鬼。。
这个式子居然有大佬能化出来真是跪了。。。。。。
注意文中的 f [ i ] = 1 i f[i] = \frac {1} {i} f[i]=i1是错的。
看代码就知道是 f [ i ] = 1 i ! f[i] = \frac {1} {i!} f[i]=i!1

AC Code:

#include<bits/stdc++.h>
#define maxn 100005
#define mod 998244353
#define LL long long
using namespace std;
 
int wlen,w[maxn]={1},r[maxn],lg[maxn],inv[maxn]={1,1},fac[maxn]={1,1},invf[maxn]={1,1};
int Pow(int base,int k){
    int ret = 1;
    for(;k;k>>=1,base=1ll*base*base%mod)
        if(k&1)
            ret=1ll*ret*base%mod;
    return ret;
}
void Init(int n){
    for(wlen=1;n>=2*wlen;wlen<<=1);
    for(int i=1,pw=Pow(3,(mod-1)/(2*wlen));i<=2*wlen;i++) w[i] = 1ll * w[i-1] * pw % mod;
    for(int i=2;i<=2*wlen;i++) lg[i] = lg[i>>1] + 1;
    for(int i=2;i<=2*wlen;i++) inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod,
        fac[i] = 1ll * fac[i-1] * i % mod,
        invf[i] = 1ll * invf[i-1] * inv[i] % mod;
}
 
void NTT(int *A,int n,int tp){
    int lgn = lg[n];
    for(int i=0;i<n;i++) r[i] = (r[i>>1]>>1) | ((i&1)<<(lgn-1));
    for(int i=0;i<n;i++) if(i<r[i]) swap(A[i],A[r[i]]);
    for(int L=2;L<=n;L<<=1)
        for(int st=0,l=L>>1,inc=wlen/l;st<n;st+=L)
            for(int k=st,x=0;k<st+l;k++,x+=inc)
            {
                int tmp = 1ll * (tp == 1 ? w[x] : w[2*wlen-x]) * A[k+l] % mod;
                A[k+l] = (A[k] - tmp) % mod , A[k] = (A[k] + tmp) % mod;
            }
    if(tp == -1)
        for(int i=0,invn=Pow(n,mod-2);i<n;i++)
            A[i] = 1ll * A[i] * invn % mod;
}
 
int n,k,l;
int A[maxn],B[maxn];
 
int main(){
    scanf("%d%d%d",&n,&k,&l);
    Init(4*n+2);
    for(int i=k;i<=n;i++) A[i] = invf[i];
    for(int i=0;i<=n;i++) B[i] = (i&1 ? -1 : 1) * invf[i];
    int len = 1;
    for(;len<=2*n;len<<=1);
    NTT(A,len,1),NTT(B,len,1);
    for(int i=0;i<len;i++) A[i] = 1ll * A[i] * B[i] % mod;
    NTT(A,len,-1);
    int ans = 0;
    for(int i=k;i<=n;i++)
        ans = (ans + 1ll*Pow(2,i)*Pow(fac[i],2)%mod*Pow(1ll*fac[2*i+1]*fac[n-i]%mod,mod-2)%mod*A[i]) % mod;
    ans = 1ll * ans * fac[n] % mod * l % mod;
    printf("%d\n",(ans+mod)%mod);
}
### Codeforces Problem 976C Solution in Python For solving problem 976C on Codeforces using Python, efficiency becomes a critical factor due to strict time limits aimed at distinguishing between efficient and less efficient solutions[^1]. Given these constraints, it is advisable to focus on optimizing algorithms and choosing appropriate data structures. The provided code snippet offers insight into handling string manipulation problems efficiently by customizing comparison logic for sorting elements based on specific criteria[^2]. However, for addressing problem 976C specifically, which involves determining the winner ('A' or 'B') based on frequency counts within given inputs, one can adapt similar principles of optimization but tailored towards counting occurrences directly as shown below: ```python from collections import Counter def determine_winner(): for _ in range(int(input())): count_map = Counter(input().strip()) result = "A" if count_map['A'] > count_map['B'] else "B" print(result) determine_winner() ``` This approach leverages `Counter` from Python’s built-in `collections` module to quickly tally up instances of 'A' versus 'B'. By iterating over multiple test cases through a loop defined by user input, this method ensures that comparisons are made accurately while maintaining performance standards required under tight computational resources[^3]. To further enhance execution speed when working with Python, consider submitting codes via platforms like PyPy instead of traditional interpreters whenever possible since they offer better runtime efficiencies especially important during competitive programming contests where milliseconds matter significantly.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值