Blue Bridge Cup questions basic training Triangle


 

Topic links : http://lx.lanqiao.cn/problem.page?gpid=T10


Subject description:

Resource constraints
Time limit: 1.0s Memory Limit: 256.0MB
Problem Description
Triangle known as Pascal triangle, its first row i + 1 is (a + b) i-expanding coefficient. 
It is an important property: triangles each number equal to its two shoulders numbers together.
We are given below of the first four rows Triangle:
  

   1

  

  1 1

  

 1 2 1

  

1 3 3 1

  

Given n, the first n rows outputs it.

Input Format

Input contains a number n.

Output Format
The output of the first n rows Triangle. Each row from the first row are sequentially output number, using one intermediate spaces. Please do not print extra spaces in front.
Sample input
4
Sample Output
1
1 1
1 2 1
1 3 3 1
Data size and convention
1 <= n <= 34。

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int MAXN=100;
 4 int a[MAXN][MAXN];
 5 int main(){
 6     int n;
 7     cin>>n;
 8     for(int i=0;i<n;i++){
 9         a[i][0]=a[i][i]=1;
10         for(int j=1;j<i;j++){
11             a[i][j]=a[i-1][j]+a[i-1][j-1];
12         }
13     }
14     for(int i=0;i<n;i++){
15         for(int j=0;j<=i;j++){
16             cout<<a[i][j]<<"   ";
17         }
18         cout<<endl;
19     }
20     return 0;
21 }

 

 

Guess you like

Origin www.cnblogs.com/ZKYAAA/p/12357219.html