注册 登录
编程论坛 Python论坛

Maple程序改写python

yyn0452 发布于 2012-04-05 16:24, 1437 次点击
Maple:
Cr := proc( x::integer, n::list(integer) ) option remember;
    t := add(i,i=n);
if min(op(n)) < 0 or x < 0 or x > t or x > 2*(t-max(op(n))) + 1 then 0
elif x=0 then     if nops(n) <= 1 or max(op(2..-1,n))=0 then 1
else 0 fielse ns2 := n[2..-1];     ns3 := sort(ns2);     
while nops(ns3) > 0 and ns3[1] = 0 do ns3 := subsop(1=NULL,ns3) od;     
if ns3 <> ns2 then RETURN( Cr(x,[n[1],op(ns3)]) )     
elif x < nops(ns3) then RETURN(0)
     elif x = nops(ns3) then RETURN( mul(i!,i=n) * nops(ns3)! / t! )
     fi;
     r := n[1]/t * Cr( x, subsop(1=n[1]-1,n) );
     for i from 2 to nops(n) do if n[i] > 0
then         r := r + n[i]/t * Cr( x-1, subsop( 1=n[i]-1, i=n[1], n ))
     fi od;     
r
fiend:

只有本站会员才能查看附件,请 登录


求高手改成python版的,我写了一部分,运行有错。。求指点
0 回复
1