我如何计算在给定的行和列杨辉三角多少? [英] How can I calculate the number at a given row and column in Pascal's Triangle?

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

问题描述

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

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。

...should be a 2.

我可以使用C或C ++或C#这样做; code或伪code AP preciated!

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

推荐答案

帕斯卡三角包含二项式系数 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.

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

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