Download - Informatica. Clasa a 11-a
![Page 1: Informatica. Clasa a 11-a](https://reader033.vdocuments.pub/reader033/viewer/2022061503/568145d8550346895db2dc3e/html5/thumbnails/1.jpg)
Anatol Gremalschi, 2004 1
Informatica. Clasa a 11-a
Metoda reluării
![Page 2: Informatica. Clasa a 11-a](https://reader033.vdocuments.pub/reader033/viewer/2022061503/568145d8550346895db2dc3e/html5/thumbnails/2.jpg)
Anatol Gremalschi, 2004 2
Ne amintim mai întîi tehnica Greedy
Datele iniţiale:
},,,{ 21 naaaA Soluţia problemei:
AxxxxX k ),,,,( 21 Ideia tehnicii Greedy:
alegem cîte un element din mulţimea A şi îl includem în vectorul X
mulţimea
vectorul
![Page 3: Informatica. Clasa a 11-a](https://reader033.vdocuments.pub/reader033/viewer/2022061503/568145d8550346895db2dc3e/html5/thumbnails/3.jpg)
Anatol Gremalschi, 2004 3
Schema generală a algoritmului Greedy
while ExistaElemente do begin AlegeUnElement(x); IncludeElementul(x); end
![Page 4: Informatica. Clasa a 11-a](https://reader033.vdocuments.pub/reader033/viewer/2022061503/568145d8550346895db2dc3e/html5/thumbnails/4.jpg)
Anatol Gremalschi, 2004 4
Datele iniţiale în metoda reluării
Mulţimile:
};,,{11,12111 maaaA
};,,{22,22212 maaaA
...
}.,,{ ,21 nnmnnn aaaA
![Page 5: Informatica. Clasa a 11-a](https://reader033.vdocuments.pub/reader033/viewer/2022061503/568145d8550346895db2dc3e/html5/thumbnails/5.jpg)
Anatol Gremalschi, 2004 5
Soluţia în metoda reluării
Spaţiul soluţiilor:
nAAAS 21
Soluţia: ),,,,( 21 nxxxX
unde ;11 Ax ;22 Ax ..., .nn Ax
![Page 6: Informatica. Clasa a 11-a](https://reader033.vdocuments.pub/reader033/viewer/2022061503/568145d8550346895db2dc3e/html5/thumbnails/6.jpg)
Anatol Gremalschi, 2004 6
Ideia metodei reluării
1. Presupunem că la pasul k am calculat deja valorile:
),,,( 21 kxxx
2. Selectăm din mulţimea Ak+1 valoarea xk+1:
),,,,( 121 kk xxxx
3. Dacă ),,,,( 121 kk xxxx satisface condiţiile
problemei, trecem la pasul k+2.
În caz contrar revenim la pasul k şi alegem alt xk.
![Page 7: Informatica. Clasa a 11-a](https://reader033.vdocuments.pub/reader033/viewer/2022061503/568145d8550346895db2dc3e/html5/thumbnails/7.jpg)
Anatol Gremalschi, 2004 7
Căutarea soluţiei prin metoda reluării
01
1
10
k := 1
k k:= + 1
a 1 ,1
a 2 ,1
a 1 2,
a 2 ,2
a 3 ,1a 3 ,2 a 3 ,30
k k:= + 1 k k-:= 1k k:= + 1
1
A 1
A 2
A 3
0 0
![Page 8: Informatica. Clasa a 11-a](https://reader033.vdocuments.pub/reader033/viewer/2022061503/568145d8550346895db2dc3e/html5/thumbnails/8.jpg)
Anatol Gremalschi, 2004 8
Schema generală a algoritmului recursiv bazat pe metoda reluării
procedure Reluare(k:integer);begin if k<=n then begin X[k]:=PrimulElement(k); if Continuare(k) then Reluare(k+1); while ExistaSuccesor(k) do begin X[k]:=Succesor(k); if Continuare(k) then Reluare(k+1) end; { while } end { then } else PrelucrareaSolutiei;end; {Reluare}
![Page 9: Informatica. Clasa a 11-a](https://reader033.vdocuments.pub/reader033/viewer/2022061503/568145d8550346895db2dc3e/html5/thumbnails/9.jpg)
Anatol Gremalschi, 2004 9
Clasificarea problemelor
1. Mulţimile A1, A2, ..., An sînt cunoscute.
3. Elementele din care sînt formate mulţimile A1, A2, ..., An şi numărul n sînt necunoscute.
2. Sînt cunoscute elementele din care sînt formate mulţimile A1, A2, ..., An, numărul n fiind necunoscut.
![Page 10: Informatica. Clasa a 11-a](https://reader033.vdocuments.pub/reader033/viewer/2022061503/568145d8550346895db2dc3e/html5/thumbnails/10.jpg)
Anatol Gremalschi, 2004 10
Exemplul 1. Problema din manual, pag. 39
Se consideră mulţimile A1, A2, ..., An, fiecare mulţime fiind formată din mk numere naturale. Selectaţi din fiecare mulţime cîte un număr în aşa mod încît suma lor să fie egală cu q.
![Page 11: Informatica. Clasa a 11-a](https://reader033.vdocuments.pub/reader033/viewer/2022061503/568145d8550346895db2dc3e/html5/thumbnails/11.jpg)
Anatol Gremalschi, 2004 11
Exemplul 1. Reprezentarea datelor
const mmax=50; { numărul maximal de mulţimi } nmax=50; { numărul maximal de elemente }
type Natural = 0..MaxInt; Multime = array[1..nmax] of Natural;
var A : array[1..nmax] of Multime; n : 1..nmax; { numărul de mulţimi } M : array[1..nmax] of 1..mmax; { cardinalul mulţimii S[k] } X : array[1..nmax] of 1..mmax; { indicii elementelor selectate } q : Natural; k, j : integer; Indicator : boolean;
![Page 12: Informatica. Clasa a 11-a](https://reader033.vdocuments.pub/reader033/viewer/2022061503/568145d8550346895db2dc3e/html5/thumbnails/12.jpg)
Anatol Gremalschi, 2004 12
Function PrimulElement
function PrimulElement(k : integer) : Natural;begin PrimulElement:=1;end; {PrimulElement }
![Page 13: Informatica. Clasa a 11-a](https://reader033.vdocuments.pub/reader033/viewer/2022061503/568145d8550346895db2dc3e/html5/thumbnails/13.jpg)
Anatol Gremalschi, 2004 13
function Continuare(k : integer) : boolean;var j : integer; suma : Natural;begin suma:=0; for j:=1 to k do suma:=suma+A[j, X[j]]; if ((k<n) and (suma<q)) or ((k=n) and (suma=q)) then Continuare:=true else Continuare:=false;end; { Continuare }
Function Continuare
![Page 14: Informatica. Clasa a 11-a](https://reader033.vdocuments.pub/reader033/viewer/2022061503/568145d8550346895db2dc3e/html5/thumbnails/14.jpg)
Anatol Gremalschi, 2004 14
function ExistaSuccesor(k : integer) : boolean;begin ExistaSuccesor:=(X[k]<M[k]);end; { ExistaSuccesor }
Function ExistaSuccesor
![Page 15: Informatica. Clasa a 11-a](https://reader033.vdocuments.pub/reader033/viewer/2022061503/568145d8550346895db2dc3e/html5/thumbnails/15.jpg)
Anatol Gremalschi, 2004 15
procedure Reluare(k : integer); { Metoda reluarii - varianta recursiva }begin if k<=n then begin X[k]:=PrimulElement(k); if Continuare(k) then Reluare(k+1); while ExistaSuccesor(k) do begin X[k]:=Succesor(k); if Continuare(k) then Reluare(k+1); end { while } end { then } else PrelucrareaSolutiei;end; { Reluare }
Procedure Reluare
![Page 16: Informatica. Clasa a 11-a](https://reader033.vdocuments.pub/reader033/viewer/2022061503/568145d8550346895db2dc3e/html5/thumbnails/16.jpg)
Anatol Gremalschi, 2004 16
123
j
iC
12
......
3B
n
1 2 31 2 ... m...
Exemplul 2. Labirintul (pag. 42)
![Page 17: Informatica. Clasa a 11-a](https://reader033.vdocuments.pub/reader033/viewer/2022061503/568145d8550346895db2dc3e/html5/thumbnails/17.jpg)
Anatol Gremalschi, 2004 17
Labirintul. Formularea matematică
Mulţimile:},,,{1 StîngaJosDreaptaSusA },,,{2 StîngaJosDreaptaSusA
...Soluţia:
},,,,,
,,,,,{
JosJosJosJosDreaptaDreapta
DreaptaJosDreaptaDreaptaDreaptaX
},,,{3 StîngaJosDreaptaSusA
![Page 18: Informatica. Clasa a 11-a](https://reader033.vdocuments.pub/reader033/viewer/2022061503/568145d8550346895db2dc3e/html5/thumbnails/18.jpg)
Anatol Gremalschi, 2004 18
Exemplul 3. Domino
Piesele iniţiale “Tren” format din 3 piese
![Page 19: Informatica. Clasa a 11-a](https://reader033.vdocuments.pub/reader033/viewer/2022061503/568145d8550346895db2dc3e/html5/thumbnails/19.jpg)
Anatol Gremalschi, 2004 19
Calculul mulţimilor A1, A2, ..., An
)}6,6(),0,3(),5,3(),6,3{(1 A
)}6,6(),0,3(),5,3{(2 A
Includem (3, 6) în tren.
Includem (6, 6) în tren.
)}0,3(),5,3{(3 A
![Page 20: Informatica. Clasa a 11-a](https://reader033.vdocuments.pub/reader033/viewer/2022061503/568145d8550346895db2dc3e/html5/thumbnails/20.jpg)
Anatol Gremalschi, 2004 20
Exemplul 4. Speologie
IZ VO A R E
S TA L A C T IT E
L IL IE C I
IE S IR E
S TA L A G M IT E
IN T R A R E
![Page 21: Informatica. Clasa a 11-a](https://reader033.vdocuments.pub/reader033/viewer/2022061503/568145d8550346895db2dc3e/html5/thumbnails/21.jpg)
Anatol Gremalschi, 2004 21
Exemplul 4. Speologie (planul labirintului este necunoscut)
function UndeMaAflu : string – returnează un şir de caractere ce conţine denumirea peşterii în care în prezent se află speologul, două puncte şi denumirile de intrări de galerii, separate prin spaţiu.
LILIECI: STALAGMITE IZVOARE LILIECI LILIECI
Exemplu:
![Page 22: Informatica. Clasa a 11-a](https://reader033.vdocuments.pub/reader033/viewer/2022061503/568145d8550346895db2dc3e/html5/thumbnails/22.jpg)
Anatol Gremalschi, 2004 22
Calculul mulţimilor A1, A2, ..., An
A1 – peştera INTRARE:
A1 = {STALACTITE, STALAGMITE}
A3 – peştera IZVOARE:
A2 = {STALACTITE, IESIRE, LILIECI}
A2 – peştera STALACTITE:
A2 = {INTRARE, IZVOARE}
![Page 23: Informatica. Clasa a 11-a](https://reader033.vdocuments.pub/reader033/viewer/2022061503/568145d8550346895db2dc3e/html5/thumbnails/23.jpg)
Anatol Gremalschi, 2004 23
Vă mulţumesc pentru atenţie !