Blue Bridge Cup-Yang Hui triangle (base!) )

Source: Internet
Author: User

Yang Hui triangle time limit: 1.0s memory limit: 256.0MBProblem description

The Yang Hui triangle is also called the Pascal Triangle, and its i+1 line is the expansion coefficient of (a+b)i .

  

One of its important properties is that each number in the triangle is equal to the number of its two shoulders.

  

The first 4 lines of the Yang Hui triangle are given below:

  

1

  

1 1

  

1 2 1

  

1 3 3 1

  

Gives N and outputs its first n rows.

Input format

The input contains a number n.

The output format outputs the first n rows of the Yang Hui Triangle. Each line starts with the first number in the line, and is separated by a space. Do not print extra spaces in front of you. Example input 4 Sample Output 1
1 1
1 2 1
1 3 3 1 Data size and convention 1 <= N <= 34.

AC Code:

#include <cstdio> #include <cstring> #include <algorithm>using namespace std;const int maxn = 35;int a[ MAXN][MAXN]; void Init () {for (int i=1; i<=34; i++) {a[i][1] = 1; a[i][i] = 1;} for (int i=3, i<=34; i++) {for (int j=2; j<=i-1;j++) {a[i][j] = A[i-1][j] + a[i-1][j-1];}}}  int main () {init (); int N;while (scanf ("%d", &n)! = EOF) {for (Int. I=1; i<=n; i++) {for (int j=1; j<i; J + +) {printf ("%d ", A[i][j]);} printf ("%d\n", A[i][i]);}} return 0;}



Blue Bridge Cup-Yang Hui triangle (base!) )

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.