|
|
back to boardbrute-force I don`t understant brute-force , who can give your code to me ? mail: k13795263@yahoo.cn Edited by author 23.08.2008 05:40 Re: brute-force I have a brute-force code for cheking answers Python 3.8 def summa(a): ans = 0 for i in range(len(a)): ans += a[i] * a[i - 1] return ans def recursion(n, do_etogo): a = True mn = 10 ** 9 mx = 0 mnansn = [] mxansn = [] for i in range(2, n + 1): if i in do_etogo: continue a = False mnans, mxans, mnansm, mxansm = recursion(n, do_etogo + [i]) if mnans < mn: mn = mnans mnansn = [mnansm] elif mnans == mn: mnansn.append(mnansm) if mxans > mx: mx = mxans mxansn = [mxansm] elif mxans == mx: mxansn.append(mxansm) if a: return summa(do_etogo), summa(do_etogo), do_etogo, do_etogo return mn, mx, mnansn, mxansn n = int(input()) print(recursion(n, [1])) |
|
|