母函数应用的实践(改变条件)
不定方程解的个数,注意这里是求不小于
x+y+z+p+q<=j,
用母函数能够解得答案是:
{ C(n-1+0,n-1) + C(n-1+1,n-1) + C(n-1+2,n-1) +...C(n-1+j,n-1) }
GO
上面式子已经被计算过了为:
C(n-1+{j+1},n-1)
其中n=5,j=10,而对于公式中n应该为6,所以有n-1
下面写程序来证明:
(defun pow (num count)
(if (or (> count 1) (eq count 1) )
(* num
(pow num
(- count 1) ) )
1))
(defun slayer ( count)
(if (or (> count 1) (eq count 1) )
(* count
(slayer
(- count 1) ) )
1))
(defun slayerex (num count)
(if (or (> count 1) (eq count 1) )
(* num
(slayerex
(- num 1)
(- count 1) ) )
1))
(defun exprhelp ( count n )
(if (> n 0)
(+ (expr (- count 1)
(- n 1) )
(exprhelp count
(- n 1)))
0))
//注意下面代码的改变之处(if (eq count 0) 1
(defun expr (count n)
(if (eq n 0)
1
(if (eq count 0)
1
(+ (exprhelp count
n)
(expr (- count 1)
n)))))
(defun formula (count n)
(/ (slayerex count
n)
(slayer n)))
(defun test (n)
(if (> n 1)
(progn
(print (expr 5 (1- n)))
(print 'compare)
(print (formula (+ 5 (1- n) -1 1) (1- n)))
(test (- n 1)))
(print 'over)))
(test 10)
注意这里代码与前面的不同之处!