一道杨辉三角(pascal)的题
3.consty=2009;maxn=50;varn,i,j,s:longint;c:array[0..maxn,0..maxn]oflongint;begins:=0;...
3.
const
y = 2009;
maxn = 50;
var
n,i,j,s:longint;
c:array[0..maxn,0..maxn]of longint;
begin
s := 0;
read(n);
c[0,0] := 1;
for i := 1 to n do
begin
c[i,0] := 1;
for j := 1 to i - 1 do
c[i,j] := c[i-1,j-1] + c[i-1,j];
c[i,i] := 1;
end;
for i := 0 to n do
s := (s + c[n,i]) mod y;
write(s);
end.
输入:17
输出:______
答案487 怎样算的啊我知道杨辉三角的过程,要一步步算吗?有简便算法吗
呃..........是说拿笔在纸上算 .那该怎样? 展开
const
y = 2009;
maxn = 50;
var
n,i,j,s:longint;
c:array[0..maxn,0..maxn]of longint;
begin
s := 0;
read(n);
c[0,0] := 1;
for i := 1 to n do
begin
c[i,0] := 1;
for j := 1 to i - 1 do
c[i,j] := c[i-1,j-1] + c[i-1,j];
c[i,i] := 1;
end;
for i := 0 to n do
s := (s + c[n,i]) mod y;
write(s);
end.
输入:17
输出:______
答案487 怎样算的啊我知道杨辉三角的过程,要一步步算吗?有简便算法吗
呃..........是说拿笔在纸上算 .那该怎样? 展开
3个回答
展开全部
用组合,第x行第y列的数=组合C(x-y+1,y)
用代码:
s:=1;
for i:=y downto x-(x-y+1)+1 do
s:=s*i;
用代码:
s:=1;
for i:=y downto x-(x-y+1)+1 do
s:=s*i;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询