本文共 442 字,大约阅读时间需要 1 分钟。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | # -*- coding:utf-8 -*- __author__ = 'Abel Xu' def func(n): """ T(n) = 4T(n/2)+n = 2n^2-n :param n: :return: """ if n = = 0 : return 0 return 4 * func(n / 2 ) + n # 另一套写法 f = lambda x: x and 4 * f(x / 2 ) + x or 0 if __name__ = = '__main__' : for i in xrange ( 0 , 6 , 2 ): print (func(i)) print f( 4 ) |