• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            1430 Binary Stirling Numbers 斯特靈數

            Binary Stirling Numbers
            Time Limit: 1000MS Memory Limit: 10000K
            Total Submissions: 1040 Accepted: 346

            Description

            The Stirling number of the second kind S(n, m) stands for the number of ways to partition a set of n things into m nonempty subsets. For example, there are seven ways to split a four-element set into two parts:

            {1, 2, 3} U {4}, {1, 2, 4} U {3}, {1, 3, 4} U {2}, {2, 3, 4} U {1}
            
            {1, 2} U {3, 4}, {1, 3} U {2, 4}, {1, 4} U {2, 3}.


            There is a recurrence which allows to compute S(n, m) for all m and n.

            S(0, 0) = 1; S(n, 0) = 0 for n > 0; S(0, m) = 0 for m > 0;
            S(n, m) = m S(n - 1, m) + S(n - 1, m - 1), for n, m > 0.


            Your task is much "easier". Given integers n and m satisfying 1 <= m <= n, compute the parity of S(n, m), i.e. S(n, m) mod 2.


            Example

            S(4, 2) mod 2 = 1.


            Task

            Write a program which for each data set:
            reads two positive integers n and m,
            computes S(n, m) mod 2,
            writes the result.

            Input

            The first line of the input contains exactly one positive integer d equal to the number of data sets, 1 <= d <= 200. The data sets follow.

            Line i + 1 contains the i-th data set - exactly two integers ni and mi separated by a single space, 1 <= mi <= ni <= 10^9.

            Output

            The output should consist of exactly d lines, one line for each data set. Line i, 1 <= i <= d, should contain 0 or 1, the value of S(ni, mi) mod 2.

            Sample Input

            1
            4 2

            Sample Output

            1

            Source


            判斷第二類斯特靈數模 2 的余數。

            在劉汝佳的黑書上有詳細解答,基本思路是枚舉數值較小的斯特靈數,從中尋找規律。

            下面這幅圖是從維基百科截出來的,有一個二進制斯特靈數與組合數的轉化公式。而組合數模二的余數就很容易了。

            我們知道,組合數C(N,M)=N ! / M ! /(N-M)!,因而只需求得階乘質因數分解式中二的重數即可解決問題。
            而N !質因數分解后2的重數可用下式來計算之。
            K=N/2+N/2^2+N/2^3+....
            上式的除法全是下取整。(可參見任何一本初等數論課本,如北大潘承洞編的那本《初等數論》)。

            這樣,這個問題就迎刃而解。

            另外,有一點說明的是上面那個圖形,就是分形幾何中一個很重要的例子——謝彬斯基墊片。楊輝三角也有類似的形狀。
            這是我用MATLAB作的一個楊輝三角的二進制圖形。

            #include <stdio.h>
            int main(int argc, char *argv[])
            {
                
                
            int n,m;
                
            int z,w1,w2;
                
            int t;
                
            int a,b,c;
                scanf(
            "%d",&t);
                
                
            while (t--)
                
            {
                    scanf(
            "%d%d",&n,&m);
                    z
            =n-(m+2)/2;
                    w1
            =(m-1)/2;
                    w2
            =z-w1;
                    a
            =0;
                    
            while (z)
                    
            {
                        z
            >>=1;
                        a
            +=z;
                    }

                    b
            =0;
                    
            while (w1)
                    
            {
                        w1
            >>=1;
                        b
            +=w1;
                    }

                    c
            =0;
                    
            while (w2)
                    
            {
                        w2
            >>=1;
                        c
            +=w2;
                    }

                    printf(
            "%d\n",(a-b-c)==0);

                }

                
                
            return 0;
            }



            posted on 2010-08-28 08:51 若余 閱讀(963) 評論(0)  編輯 收藏 引用

            導航

            <2010年8月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            2930311234

            統計

            常用鏈接

            留言簿

            隨筆檔案(16)

            搜索

            最新隨筆

            最新評論

            評論排行榜

            少妇内射兰兰久久| 国产成人无码精品久久久性色| 亚洲另类欧美综合久久图片区| 久久久午夜精品| 天天躁日日躁狠狠久久| 国产精品对白刺激久久久| 久久人人爽人人澡人人高潮AV| 久久精品国产亚洲av麻豆图片| 国产成人精品久久二区二区| 久久久久亚洲爆乳少妇无| 久久精品中文无码资源站| 久久电影网一区| 伊人色综合久久天天人手人婷| 久久久精品人妻一区二区三区蜜桃| 日产久久强奸免费的看| 91久久精品视频| 久久精品国产亚洲AV高清热| 精品久久久久久久久久久久久久久 | 欧美综合天天夜夜久久| 伊人久久大香线蕉综合Av| 精品无码久久久久久久动漫| 久久天天躁狠狠躁夜夜躁2O2O| 久久久久se色偷偷亚洲精品av| 亚洲精品国产成人99久久| 久久久久亚洲Av无码专| 亚洲国产小视频精品久久久三级 | 热re99久久精品国产99热| 久久亚洲精品国产精品| 久久精品青青草原伊人| 少妇被又大又粗又爽毛片久久黑人 | 久久久久国产精品人妻 | 欧美大香线蕉线伊人久久| 人妻无码精品久久亚瑟影视| 97精品伊人久久大香线蕉| 久久精品这里只有精99品| 色99久久久久高潮综合影院| 91久久国产视频| 性欧美大战久久久久久久| 无码乱码观看精品久久| 久久这里都是精品| 欧美一区二区三区久久综合|