Jump to content
mirrorer

Problema C++ [v2]

Recommended Posts

Enunt:

Se dau N tipuri de bancnote de valori b1,b2,b3,..bn.Din fiecare tip se dispune un numar nelimitat de bancnote.

Se defineste pentru un subset de tipuri de monede, sa-l numim X, capacitatea de acoperire a acestuia ca fiind numarul de sume cuprinse intre 1 si S (inclusiv) pe care le poate obtine folosind numai monede de tipuri aflate in subsetul X.

Se cere:

Fiind data S(o suma de bani ) , se cere suma capacitatilor de acoperire a tutoror subseturilor de monede posibile .

Restrictii:

1. N<=17

2. S<=512

Exemplu:

Pentru n=2 , bancontele de b1=2 b2=3 si S=10 lei ,trebuie sa afiseze : 17

Explicatie :

Cu subsetul {2} se pot obtine 5 sume: 2, 4, 6, 8, 10

Cu subsetul {3} se pot obtine 3 sume: 3, 6, 9

Cu subsetul {2,3} se pot obtine 9 sume: 2, 3, 4, 5, 6, 7, 8, 9, 10

Observati ca nu e obligatoriu ca toate tipurile de bancnote dintr-un subset sa fie folosite: de?exemplu suma 6 pentru ultimul subset se obtine folosind numai monede de tip “2” sau numai monede de tip “3” (daca le folosim pe amandoua nu putem obtine suma 6).

Numarul cautat va fi astfel 5+3+9=17.

Nu va pun acum sa implementati la ora asta , ci doar sa-mi spuneti o idee de rezolvare si complexitatea acesteia.

Credit : @danyweb09 ( Problema initiala )

Link to comment
Share on other sites

daca se cere doar suma capacitatilor pt toate subseturile posibile, practic trebuie sa lucrezi cu div si mod.

in primul rand, fiecare dintre b1 .. bn este de sine statator un subset, asa ca avem cel putin s div b1 + s div b2 ... s div bn posibilitati.

mai departe, o functie probabil recursiva, ceva de genul (s - 1 x b1) div b2 o rezolvare, (s - 2 x b1) div b2 a 2-a rezolvare... (s mod bn) mod bn-1) ... mod b2) div b1 cred ca ar fi ultima rezolvare.

asta e ideea mea, poate am inteles problema gresit. nu o sa stau sa programez, dar sunt curios daca e buna.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...