Coefficient of two expansion types and coefficient of two expansion types

Source: Internet
Author: User

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 '}*********************************** **********************/

 

 

 

 

Related Article

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.