原帖见:http://blog.csdn.net/d8111/archive/2008/09/21/2956832.aspx
动态语言永远是那么的飘逸。就似绝世神剑。高手用来心中有剑,低手则走火入魔。
- from time import time
- def shot(n, remain, his):
- """n goes 0-9"""
- if(remain < 0 or remain > (n + 1) * 10):
- return;
- if(n == 0):
- his[0] = remain;
- print his
- globals()["counter"] += 1
- else:
- for score in scores:
- his[n] = score;
- shot(n - 1, remain - score, his)
- if __name__ == "__main__":
- scores = range(11)
- init = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
- counter = 0
- begin=time()
- shot(9, 90, init)
- end=time()
- print counter
- print end-begin
不过貌似比较可惜的地方是,耗时27.2189998627,比起java来可慢的多咯