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!) )