ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1535. The Hobbit or There and Back Again

brute-force
Posted by lian lian 23 Aug 2008 05:35
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
Posted by zhiganov_v 29 Dec 2020 20:15
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]))