如何计算Pascal三角形中给定行和列的数字? [英] How can I calculate the number at a given row and column in Pascal's Triangle?

查看:232
本文介绍了如何计算Pascal三角形中给定行和列的数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个函数,给定一个行和列,将计算该位置在Pascal的三角形中的值。

I'm trying to create a function that, given a row and column, will calculate the value at that position in Pascal's Triangle.

val = GetPasVal(3, 2); // returns 2

这里我指定第3行第2列, :

So here I'm specifying row 3, column 2, which as you can see:

          1
         1  1
       1   2   1

...应该是2.

我可以使用C或C ++或C#做这个;代码或伪代码!

I can use C or C++ or C# to do this; code or pseudocode appreciated!

推荐答案

Pascal的三角形包含二项式系数 C(n,k);
有一个非常方便的递归公式

The Pascal's triangle contains the Binomial Coefficients C(n,k); There is a very convenient recursive formula

C(n, k) = C(n-1, k-1) + C(n-1, k)

您可以使用此公式计算二项式系数。

You can use this formula to calculate the Binomial coefficients.

这篇关于如何计算Pascal三角形中给定行和列的数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆