设为首页 加入收藏

TOP

二项展开式的系数
2017-10-12 17:39:20 】 浏览:3090
Tags:项展 开式 系数
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'}                                      *
********************************************************/

 

 

 

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇工程脚本插件方案 - c集成Python.. 下一篇C语言 时间函数的学习和总结

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目