Hdu 2032 Yang Hui triangle (Java)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.