Coefficient of two expansion types and coefficient of two expansion types
Description
Expand the binary (a + B) I, and the coefficients constitute the Yang-Hui triangle shown in 1, that is, Pascal's trangle. I can't think of it. Yang huitriangle still has this meaning. The knowledge in mathematics is closely related.
1 1 I = 1
1 2 1 2
1 3 3 1 3
1 4 6 4 1 4
1 5 10 10 5 1 5
1 6 15 20 15 6 1 6
Figure 1
Now we need to print out the expansion coefficient.Rules:This question must be solved using the "queue" data structure.
Input
There are multiple test cases, each of which occupies one row.
Each row is an integer I, 1 ≤ I ≤ 30. Indicates the power of the binary.
Output
Outputs a line for each test case, and outputs the coefficients of the two expanded items from left to right.6
2
1 6 15 20 15 6 1
1 2 1
John
I will not post the complete code. I will write down the idea, after all, once AC.
When I first saw this question, the first impression was the tree's sequence traversal. I started the simulation process with ctrl + r mspaint.
In general, it is quite simple.
# Include <stdio. h> # include <stdlib. h> # include <string. h> # include <stdbool. h> // # include <dos. h> typedef int ElemType; typedef struct Node {ElemType data; struct Node * next;} Node; typedef struct Queue {Node * front; Node * rear; int length;} Queue; queue * queue_new (); bool IsEmpty (Queue * q); bool EnQueue (Queue * q, ElemType e); bool DeQueue (Queue * q, ElemType * e ); void BlackBox (int n); int main () {int n; while (Scanf ("% d", & n )! = EOF) BlackBox (n); // system ("pause"); return 0 ;} /*************************************** * ****************** algorithm: the queue starts with two '1', repeating I = 1 to n-1 times {** repeating j = 1 to I times {** 1. team out, ** 2. add the element to the head of the team and then join the result} ** 3. join '1 '}*********************************** **********************/