首頁    課程資訊    參考資料    作業    考試    成績

作業說明(此題需附說明檔)

     目標:熟悉function及recursive

                      你的程式只要能處理到"long"(2147483647)即可,不需考慮大數情形

     題目:Binary coefficients are the constants appearing in front of the terms of the expansions

                      of powers of binary expressions. For example,  (a+b)^3=1a^3+3(a^2)b+3a(b^2)+1b^3

                      Instead of getting these numbers by Pascal's triangle, we could try to write a recursive 

                      function to implement it. As we already know, (a+b)^n=ΣC(n,i)*a^(n-i)*b^i

                                                                                                    i from 0 to n

                      You can find a rule that the leftmost and rightmost values can be stated as follows,

                      C(n,0)=1 and C(n,n)=1     for every n

                      Another rule tells you that

                      C(n,k)=C(n-1,k-1)+C(n-1,k)     for every n and k (as long as k>=1 and k<= n-1)

                      Please implement the function C(n,k) using recursion.

                      After you can calculate the value of C(n,k), please try to calculate the probabilities of a poker

                      game with five cards in one hand. The value of five cards are listed below. Write your formulas

                      about how to calculate the probability. You can't just give me the answer.

      說明:

                1.      The user can input the number of n and k (no more than 1000).

                2.   After calculating C(n,k), let the user input the value of  poker sets and output the probability.

                3.   The program terminates when the user input n=-1 and k=-1

     輸出範例:

Please input the number of n and i in C(n,i) 12   9

The value of C(12, 9) is  xxx

Please input the value of poker sets you want to know: 2

(1. straight-flush 2. four-of-a-kind 3.full-house.......)

The probability of getting "four-of-a-kind":  xxx

Please input the number of n and i in C(n,i) 9   4

…………………

Please input the number of n and i in C(n,i) -1   -1

The program is terminated.

      牌組大小

            1.straight-flush     flush of the same suit                 C9,C10,CJ,CQ,CK  
            2.four-of-a-kind   four identical numbers               C2,D2,H2,S2,D9 
            3.full-house         3 identical numbers and a pair    D8,C8,S8,S7,H7 
            4.straight              5 consecutive numbers               D5,H6,C7,C8,S9 (不含同花順)
            5.flush                  5 cards of the same suit              D3,D5,D8,D9,DQ
            6.three-of-a-kind  3 identical numbers                    C2,D2,H2,S10,D9 
            7.two-pairs           2 sets of 2 identical numbers      C2,D2,S9,C9,DJ
            8.one-pair            1 set of 2 identical numbers        C2,D2,S7,C9,DJ
            9.highest-card      none of the above                       CA,D5,C4,S9,DK

       繳交期限:92年10月28