Yang Hui Triangle, also known as Jia Xian Triangle, Pascal Triangle, is a geometric arrangement of two-term coefficients in triangles.
Premise: The number of endpoints is 1.
1. Each number equals two of the sum above it.
2, each line of the number of symmetrical symmetry, starting from 1 gradually become larger.
3, the number of the nth row has n items.
4, nth line number and for 2n-1.
5, the nth line of the number of M and the number of n-m+1 is equal, that is, C (n-1,m-1) =c (n-1,n-m) (Combinatorial number properties
one) [1]
6, each number equals the sum of the left and right two digits of the previous line. This property can be used to write out the entire Yang Hui triangle. That is, the number of n+1 in line I is equal to the sum of the number of i-1 and the number of the first n rows, which is also one of the properties of the combinatorial number. That [2]
7. The number of m in the nth row can be expressed as C (n-1,m-1) (n-1 subscript, m-1 superscript), which is a different from n-1
The number of m-1 elements in an element. (see image on right)
Combinatorial number calculation method: C (n,m) =n!/[m! ( N-M)!]
8, (A+B) ^n in the expansion of the various coefficients in turn corresponds to the Yang Hui Triangle of the first (n+1) row of each. [3]
9. The 1th digit of line 2n+1, followed by the 3rd number in line 2n+2, 5th of the 2n+3 line ... In the first line, these numbers are the 4n+1 Fibonacci numbers, and the 2nd number of rows 2n (n>1), followed by the 4th digit of line 2n-1, the 6th number of the 2n-2 line ... The sum of these numbers is the 4n-2 Fibonacci number.
10, the number of rows will be arranged, you can get 11 n-1 (n is the number of rows) the second side: 1=11^0; 11=11^1; 121=11^2 ...; The attentive person may find that when the n≥5 will not conform to the nature of this, in fact, is this: the first row of the rightmost number "1" in the bit, and then the left of a number of bits aligned to 10 bits ..., and so on, the vacancy with "0", and then add up all the numbers, The number of n-1 is exactly 11 of the time Square. Taking n=11 as an example, the number of the 11th line is: 1,10,45,120,210,252,210,120,45,10,1;
The code is as follows:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Namespace YHSJ
{
Class Program
{
static void Main (string[] args)
{
int[][] Array_int = new int[10][];//defines a two-dimensional array of 10 rows
Record the value of the Yang Hui triangle to the array
for (int i = 0; i < Array_int. Length; i++)//traverse the number of rows
{
Array_int[i] = new Int[i + 1];//defines the number of columns for a two-dimensional array
for (int j = 0; J < Array_int[i]. Length; J + +)//traverse the number of columns in a two-dimensional array
{
if (I <= 1)//If the first two lines of the array
{
ARRAY_INT[I][J] = 1;//codego.net set it to 1
Continue
}
Else
{
if (j = = 0 | | j = = Array_int[i]. LENGTH-1)//If it is the beginning or end of the line
ARRAY_INT[I][J] = 1;//set it to 1
Else
ARRAY_INT[I][J] = array_int[i-1][j-1] + array_int[i-1][j];//calculated based on the Yang Hui algorithm
}
}
}
for (int i = 0; i < Array_int. Length; i++)//output Yang Hui triangle
{
for (int j = 0; J < Array_int[i]. Length; J + +)
Console.Write ("{0}\t", array_int[i][j]);
Console.WriteLine ();
}
Console.ReadLine ();
}
}
}
This article is from the "Flying Masterpiece" blog, please be sure to keep this source http://9580476.blog.51cto.com/9570476/1608545
Yanghui three home algorithm C # code