Python ?
, . n . Python 2.7.6. , , C, , , .
import sys
sys.setrecursionlimit(100000)
sol = []
stop = False
def solve(n, k, current_sum):
global stop
if stop:
return
if current_sum == n:
stop = True
for i in xrange(0, k, 1):
print(sol[i]),
print
return
start = 1 if len(sol) == 0 else (sol[k-1] + 2)
for i in xrange(start, n + 1, 2):
if current_sum + i <= n and not stop:
sol.append(0)
sol[k] = i
solve(n, k + 1, current_sum + i)
else:
return
solve(100000000, 0, 0)
, . n = 100.000, 370 . 0 . ( Mac OS X ).
, Linux:
import os
import sys
sys.setrecursionlimit(100000)
_proc_status = '/proc/%d/status' % os.getpid()
_scale = {'kB': 1024.0, 'mB': 1024.0*1024.0,
'KB': 1024.0, 'MB': 1024.0*1024.0}
def _VmB(VmKey):
'''Private.
'''
global _proc_status, _scale
try:
t = open(_proc_status)
v = t.read()
t.close()
except:
return 0.0
i = v.index(VmKey)
v = v[i:].split(None, 3)
if len(v) < 3:
return 0.0
return float(v[1]) * _scale[v[2]]
def memory(since=0.0):
'''Return memory usage in bytes.
'''
return _VmB('VmSize:') - since
stop = False
def solve(n, used, current_sum):
global stop
if stop:
return
if current_sum == n:
print(used)
stop = True
return
start = 1 if len(used) == 0 else (used[-1] + 2)
for i in range(start, n + 1, 2):
if current_sum + i <= n and not stop:
used.append(i)
solve(n, used, current_sum + i)
used.pop()
else:
return
m0 = memory()
solve(100000, [], 0)
m1 = memory(m0)
print(m1/(1024*1024))
() , , 4 MB n, 100.000.000. .
, . , , ( ).
, , . , . . , .