• HDU 6397 组合数学+容斥 母函数


    Character Encoding

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
    Total Submission(s): 1473    Accepted Submission(s): 546


    Problem Description
    In computer science, a character is a letter, a digit, a punctuation mark or some other similar symbol. Since computers can only process numbers, number codes are used to represent characters, which is known as character encoding. A character encoding system establishes a bijection between the elements of an alphabet of a certain size n and integers from 0 to n1. Some well known character encoding systems include American Standard Code for Information Interchange (ASCII), which has an alphabet size 128, and the extended ASCII, which has an alphabet size 256.

    For example, in ASCII encoding system, the word wdy is encoded as [119, 100, 121], while jsw is encoded as [106, 115, 119]. It can be noticed that both 119+100+121=340 and 106+115+119=340, thus the sum of the encoded numbers of the two words are equal. In fact, there are in all 903 such words of length 3 in an encoding system of alphabet size 128 (in this example, ASCII). The problem is as follows: given an encoding system of alphabet size n where each character is encoded as a number between 0 and n1 inclusive, how many different words of length m are there, such that the sum of the encoded numbers of all characters is equal to k?

    Since the answer may be large, you only need to output it modulo 998244353.
     
    Input
    The first line of input is a single integer T (1T400), the number of test cases.

    Each test case includes a line of three integers n,m,k (1n,m105,0k105), denoting the size of the alphabet of the encoding system, the length of the word, and the required sum of the encoded numbers of all characters, respectively.

    It is guaranteed that the sum of n, the sum of m and the sum of k don't exceed 5×106, respectively.
     
    Output
    For each test case, display the answer modulo 998244353 in a single line.
     
    Sample Input
    4
    2 3 3
    2 3 4
    3 3 3
    128 3 340
     
    Sample Output
    1
    0
    7
    903
     

    容斥写法

    x1+x2+...+xm = k (xi>=0) 共有C(k+m-1,m-1) 种 插板法

    如果有c个违反条件 把每一个违反条件的x减去n

    x1'+x2'+x3'+x4'+x5'+...+xn'= k-c*n xi>=0 共有 C(k-c*n+m-1,m-1)种
        容斥系数    变量选法
    ans  = (-1)^c   *   C(m,c)       *     C(k-cn+m-1,m-1)

    母函数写法

    1+x+x^2+...+x^(n-1)=(1-x^n)/(1-x)

    (1+x+x^2+...+x^(n-1))^m

    =(1-x^n)^m/(1-x)^m
    =(1-x^n)^m*(1-x)^(-m)
    =(1-x^n)^m*(sum_ (x^i)*C(m+i-1,m-1)) //上篇博客说的核武器。。。。

    ans=x^k 的系数
    左边二项式展开 按照每个i 右边应该有k-ni
    ans= sum (-1)^i*C(m,i)*C(m+k-n*I-1,m-1)

    左边 x^n*i      右边x^(k-n*i)
    系数(-1)^i*C(m,i)   系数C(m+k-n*I-1,m-1)

    AC代码

    #include <bits/stdc++.h>
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define all(a) (a).begin(), (a).end()
    #define fillchar(a, x) memset(a, x, sizeof(a))
    #define huan printf("
    ");
    #define debug(a,b) cout<<a<<" "<<b<<" "<<endl;
    using namespace std;
    const int maxn= 3e5+10;
    const int inf = 0x3f3f3f3f,mod=998244353;
    typedef long long ll;
    ll fac[maxn],inv[maxn];
    void init()
    {
        fac[0]=fac[1]=1;
        inv[0]=inv[1]=1;
        for(ll i=2;i<maxn;i++)
        {
            fac[i]=fac[i-1]*i%mod;
            inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
        }
        for(ll i=2;i<maxn;i++)         
            inv[i]=inv[i-1]*inv[i]%mod;  
    }
    ll C(ll x,ll y)
    {
        if(y>x) return 0;
        if(y==0||x==0) return 1;
        return fac[x]*inv[y]%mod*inv[x-y]%mod;
    }
    int main()
    {
        ll n,m,k,t;
        init();
        cin>>t;
        while(t--)
        {
            cin>>n>>m>>k;
            if(k==0)
            {
                cout<<1<<endl;
                continue;
            }
            else if((n-1)*m<k)
            {
                cout<<0<<endl;
                continue;
            }
            int c=min(k/n,m);
            ll ans=0;
            for(int i=0;i<=c;i++)
            {
                if(i%2==0)
                    ans=(ans+C(m,i)*C(k-i*n+m-1,m-1)%mod)%mod;
                else
                    ans=(ans-C(m,i)*C(k-i*n+m-1,m-1)%mod+mod)%mod;
            }
            cout<<ans<<endl;
        }
    }
  • 相关阅读:
    Navicat Preminm12 连接Oracle数据库失败或闪退
    kafka tool报错:Error fetching datea.Offset out of range
    kafka修改默认端口号
    post发送请求,body格式
    一、线程基础、线程之间的共享和协作(1)
    jQuery(三) 动画操作一
    jQuery(二) 选择器
    jQuery(一)
    javascript面向过程与面向对象
    鼠标跟随动画: event
  • 原文地址:https://www.cnblogs.com/stranger-/p/9494119.html
Copyright © 2020-2023  润新知