1 / 8

Problema magazinului cu cele 10 raioane

Problema magazinului cu cele 10 raioane. Savaniu Marc Cls.a-XI-a B. Enuntul problemei:.

hamlin
Download Presentation

Problema magazinului cu cele 10 raioane

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Problema magazinului cu cele 10 raioane Savaniu Marc Cls.a-XI-a B

  2. Enuntul problemei: • Mixt” este numele unui magazin cu 5 etaje care are urmatoarele caracteristici:-la etajul 1 are 10 raioane cu pantofi-la etajul 2 are 10 raioane cu ciorapi-la etajul 3 are 10 raioane cu pantaloni-la etajul 4 are 10 raioane cu camasi-la etajul 5 are 10 raioane cu cravate

  3. EXEMPLU: • Presupunem ca vrem sa ne imbracam de la acest magazin,adica cumparam pantofi,ciorapi,pantaloni,camasisi cravate astfel incat acestea sa se asorteze intre ele,sa genereze toate modalitatile de a ne imbraca. • Etaj I 1 2 3 4 5 6 7 8 9 10 • Etaj II 1 2 3 4 5 6 7 8 9 10 • Etaj III 1 2 3 4 5 6 7 8 9 10 • Etaj IV 1 2 3 4 5 6 7 8 9 10 • Etaj V 1 2 3 4 5 6 7 8 9 10 • Solutie:

  4. Implementarea: • Deoarece solutia are mai multe componente adica cate etaje are magazinul vom folosi metoda BACKTRACKING. • Pentru rezolvare vom folosi urmatoarele variabile: • k-o variabila care reprezinta etajul pe care ne gasim; • st-stiva {un vector care are 5 componente} adica st[k] v-a reprezenta numarul raionului de la etajul k. • as-este o variabila de tip boolean care primeste valoarea {true} daca pe etajul k mai sunt raioane nevizitate si {false} in caz contrar; • ev-este o variabila de tip boolean care primeste valoarea {true} daca ce este la raionul st[k] ne convine iar {false} in caz contrar

  5. Algoritm: • Program magazin; • type stiva=array[1..100] of integer; • Var st:stiva; • k,n,e:integer; {n-reprez. Raioanele} • as,ev:boolean; {e-nr etajelor} • Procedure init(k:integer;var st:stiva); • begin • st[k]:=0; • End; • procedure succesor(var as:boolean; var st:stiva;k:integer); • begin • if st[k]<n then begin • as:=true; • st[k]:=st[k]+1 • else as:=false; • end;

  6. procedure valid(var ev:boolean;st:stiva;k:integer); • Begin • ev:=true; end; function solutie(k:integer):boolean; • begin • solutie:=(k=e); • end; • procedure tipar; • var i:integer; • Begin • for i:=1 to e do write(st[i]:4); • End;

  7. ALGORITM CONTINUARE: • BEGIN • write(‘cate raioane avem?’);readln(n); • write(‘cate etaje avem?’);readln(e); • k:=1; • Init(k,st); • while k>0 do begin • repeat • succesor(as,st,k); • if as then valid(ev,st,k); • until(not as) or (as end ev) • if as then • if solutie(k) then tipar • else begin • k:=k+1; • init(k,st); • end • else k:=k-1; • end.

  8. Finish: • Prezentarea a fost realizata de elevul • Savaniu Marc

More Related