Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Bitnami MediaWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
2646 - impartire
(section)
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Rezolvare == <syntaxhighlight lang="python3" line="1"> def verificare_restrictii(n, numbers): # Verifică dacă n este un număr par și se află în intervalul [2, 18] if n % 2 != 0 or n < 2 or n > 18: return False, "Numărul n nu corespunde restricțiilor." # Verifică restricțiile pentru numerele naturale for num in numbers: if num >= 1000: return False, "Numerele nu corespund restricțiilor." return True, "" def calculeaza_suma_resturilor(permutare): return sum(permutare[i] % permutare[i+1] for i in range(0, len(permutare), 2)) def backtracking(permutare, vizitate, n, numbers, suma_minima): if len(permutare) == n: suma = calculeaza_suma_resturilor(permutare) suma_minima[0] = min(suma_minima[0], suma) return for i in range(n): if not vizitate[i]: permutare.append(numbers[i]) vizitate[i] = True backtracking(permutare, vizitate, n, numbers, suma_minima) permutare.pop() vizitate[i] = False def main(): # Citire număr n de la tastatură n = int(input("Introduceți numărul n: ")) # Verificare restricții valid, mesaj_eroare = verificare_restrictii(n, []) if not valid: print("Eroare:", mesaj_eroare) return # Citire cele n numere naturale de la tastatură numbers = list(map(int, input("Introduceți cele {} numere naturale separate prin spații: ".format(n)).split())) # Verificare restricții pentru numerele introduse valid, mesaj_eroare = verificare_restrictii(n, numbers) if not valid: print("Eroare:", mesaj_eroare) return permutare = [] vizitate = [False] * n suma_minima = [float('inf')] backtracking(permutare, vizitate, n, numbers, suma_minima) print("Suma minimă a resturilor este:", suma_minima[0]) if __name__ == "__main__": main() </syntaxhighlight>
Summary:
Please note that all contributions to Bitnami MediaWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Bitnami MediaWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width