二项展开式的系数

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了二项展开式的系数相关的知识,希望对你有一定的参考价值。

Description

将二项式 ( a + b )i展开,其系数构成如图1所示的杨辉三角形,也即Pascal‘s trangle。想不到吧,杨辉三角形还有这种意义呢,数学里面的知识之间的关系真是千丝万缕啊。

         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

图1

现在要求将展开式系数打印出来。   规定:本题必须采用“队列”这种数据结构来解决。

Input

有多个测试用例,每个测试用例占一行。

每行是一个整数 i, 1 ≤ i ≤ 30 。表示该二项式的幂。

Output

对每个测试用例输出一行,从左到右输出该二项展开式的各项的系数,各数6

2
1 6 15 20 15 6 1

1 2 1
John

就不贴完整代码了,写一下思路,毕竟一次AC。

刚开始看到这题,第一印象就是树的层序遍历,就开始ctrl+r mspaint 开始模拟过程

总的来说还是挺简单的。

#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;
}

/********************************************************
*    算法:队列中开始有两个‘1‘,循环i=1 to n-1次{          *
*        循环j=1 to i次{                                 *
*            1.出队,                                    *
*            2.得到的元素与队头元素相加再将结果入队 }       *
*        3.入队‘1‘}                                      *
********************************************************/

 

 

 

 

以上是关于二项展开式的系数的主要内容,如果未能解决你的问题,请参考以下文章

二项式系数的和是啥?

二项式系数的和与各项系数的和怎么求,公式?

求:WPF中TreeView如何实现展开一个节点其他节点关闭!

多项式的系数怎么求

每日一小练——二项式系数加法解

二项式定理