Daily algorithm ---- Pascal's Triangle

Pascal's Triangle

  1. Each number is equal to the sum of the two numbers above it.
  2. Each row of numbers symmetrically by 1 is gradually increased.
  3. Digital line n has n items.
  4. Number m of n-th row may be represented as C (n-1, m-1), that is, taking the number of combinations m-1 elements different from the n-1 elements.
  5. The number m of the n-th row and the n-m + 1 number equal to the number one combination of properties.
  6. Each digit equal to the previous line and about two numbers. This property can be used to write the entire Pascal's Triangle. I.e. the n + 1 i-th row is equal to the number of i-1 and i-th and the n-th row sum, one of which is a combination of several properties. I.e., C (n + 1, i) = C (n, i) + C (n, i-1).
  7. (A + b) Expanding the factor n in the corresponding sequence of (n + 1) Pascal's triangle in each row.
  8. The first number 2n + 1 of the first row, the second with 2n + 2 number of the third row, the row number of 2n + 3 ...... 5 in a line, and the first of these numbers 4n + 1 th Fibonacci lease number; the first row of the second number 2n (n> 1), with the first 2n-1 number of row 4, line number 2n-2 6 ...... sum of these first and 4n-2 th Fei the number of waves that deed.
  9. The number n-th row are multiplied by 10 ^ (m-1), wherein the number of columns m for is located, and then added to the 11 ^ (n-1). 11 ^ 0 = 1,11 ^ 1 = 1x10 ^ 0 + 1 × 10 ^ 1 = 11,11 ^ 2 = 1 × 10 ^ 0 + 2x10 ^ 1 + 1x10 ^ 2 = 121,11 ^ 3 = 1x10 ^ 0 + 3 × 10 ^ 1 + 3x10 ^ 2 + 1x10 ^ 3 = 1331,11 ^ 4 = 1x10 ^ 0 + 4x10 ^ 1 + 6x10 ^ 2 + 4x10 ^ 3 + 1x10 ^ 4 = 14641,11 ^ 5 = 1x10 ^ 0 + 5x10 ^ 1 + 10x10 ^ 2 + 10x10 ^ 3 + 5x10 ^ 4 + 1 × 10 ^ 5 = 161051.
  10. and n is the row number 2 ^ (n-1). 1 = ^ 2 (1-0), 1 + 1 = 2 ^ (2-1), 1 + 2 + 1 = ^ 2 (3-1), 3 + 3 + 1 + 1 = 2 ^ (4-1 ), 1 + 4 + 6 + 4 + 1 = ^ 2 (5-1), 1 + 5 + 10 + 10 + 5 + 1 = ^ 2 (6-1).
  11. Any of a number equal to the diagonal upper right corner thereof, the numbers on the corners. 1 + 2, 1 + 1 = 1 + 1 + 1 = 3,1 + 4,1 + 1 + 1 = 2 + 3,1 = 6,1 = 2 + 3 + 2 + 3 + 4 = + 10,1 3 = 3 + 4,1 + 6 + 4 = 10, 1 = 5.
  12. The numbers to the left of each row are aligned, which top right to bottom left diagonal equal Fibonacci numbers Fibonacci sequence of digital data. 1, 1 + 1 = 2, 2 + 1 = 3 + 1 = 3,1 + 5,3 + 8,1 + 4 + 1 = 5 + 1 = 6 + 10 + 6 + 13, 4 + 1 = 21,1 + 7 + 10 + 15 + 20 + 1 = 34,5 + 21 + 8 + 1 = 55.


 /**
     * 打印杨辉三角
     *  是 二项式系数 在三角形中的一种几何排序
     */
    public function test()
    {
        echo "<pre>";
        $arr = [];
        $N = 10; //打印几层
        for($i = 0; $i<$N; $i++) { //几层
            for($m = 0;$m<$N-$i;$m++) {
                print_r(' ');
            }
            for($j = 0; $j<=$i; $j++)
            {
                if((0 == $j)||($i == $j)){
                    $arr[$i][$j] = 1;
                }else{
                    $arr[$i][$j] = $arr[$i-1][$j] + $arr[$i-1][$j-1];
                }
                print_r($arr[$i][$j]);
            }
            print_r("\n");
        }
    }

Guess you like

Origin www.cnblogs.com/zhy7blog/p/11247696.html
Recommended