Problem:
The subject asks to see the law of Yang Hui Triangle, namely: a[i][j]=a[i-1][j-1]+a[i-1][j];
At the time of output, the first column has no output, because the J parameter is set to start from 1, so it is changed to 0, with the if to meet J from the beginning of the demand.
Yang Hui TriangleTime
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 43154 Accepted Submission (s): 18128
Problem description Remember the Yang Hui triangle you learned in high school? Specific definitions are no longer described here, you can refer to the following graphs:
1
1 1
1 2 1
1 3 3 1
1 4 6) 4 1
1 5 10 10 5 1
Input data contains multiple test instances, and each test instance input contains only one positive integer n (1<=n<=30), representing the number of layers of the Yang Hui triangle that will be output.
Output corresponds to each input, export the Yang Hui triangle of the corresponding number of layers, separated by a space between the integers of each layer, and a blank line behind each Yang Hui triangle.
Sample Input
2 3
Sample Output
11 111 11) 2 1
Code:
Import java.util.*;p ublic class main{public static void Main (String args[]) {Scanner cin=new Scanner (system.in); while ( Cin.hasnext ()) {int n=cin.nextint (); int[][] A=new int[30][30]; for (int i=0;i<n;i++) {a[i][0]=1;for (int j=0;j<=i; J + +) {if (j>0) a[i][j]=a[i-1][j-1]+a[i-1][j];if (j<i) System.out.print (a[i][j]+ ""); ElseSystem.out.println (a[i ][J]);}} System.out.println ();}}}
Hdu 2032 Yang Hui triangle (Java)