際際滷

際際滷Share a Scribd company logo
Elev: Sima Marcel Cls a XI-a B
Enuntul problemei Se consider  un triunghi de numere naturale format din n linii. Prima linie con釘ine un numr,a doua dou numere, ... ,iar ultima,n numere naturale. Cu ajutorul acestui triunghi se pot forma sume de numere naturale 樽n felul urmtor: Se pornete cu numrul de pe linia 1; Succesorul unui numr se afl pe linia urmatoare plasat sub el(aceeai   coloan) sau pe diagonal la dreapt(coloana crete cu 1);
Pentru linia i pentru  i<n se obtine astfel: C[i,j]=max{T[i,j]+C[i+1,j],T[i,j]+ +C[i+1,j+1]} i:=1,n-1; j:=1,i;
T: 2 3 3 5 5 6 6 4 4 1 5 6 1 4 12 9 9 9 8 7 C: 6 6 6 + + + + + + 5 = = = = = = 11 11 12 < < < < 3 3 6 1 4 > 4 3 3 3 4 4 4 + + + + + 1 = = = = = 5 5 8 6 6 6 9 > 5 5 3 4 8 8 9 9 2 2 + = 3 5 5 5 7 12 8 9 9 9 7
2 3 3 5 5 6 6 4 4 1 T: 5 6 1 4 C: 12 9 9 6 6 6 + + + + 5 = = = = 11 11 12 < 3 3 6 1 4 > 4 8 + = = < 4 4 4 + 1 5 5 8 12 + + + + + + 5 = = = = = = 17 3 3 9 12 15 15 12 5 9 8 14 14 13 13 > > 2 2 15 14 17 16 16 > 12 9 8 15 14 17
Algoritmul  Pentru etapa i se trateaz linia i a triunghiului. Fie un ir de n numere care respect condi釘iile prolemei i care formeaz suma maxim, de aici considerm numrul care a fost preluat de pe linia i;vom forma un triunghi de la baz la v但rf cu sumele maxime care se pot forma cu fiecare numr.ntr-o matrice T citim  t riunghiul de numere si 樽ntr-o matrice C vom avea urmtoarele rela釘ii:
C [n,1]:=T[n,1];  T[1,1]=2; T[4,1]=5; C[n,2]:=T[n,2];  T[2,1]=3; T[4,2]=6; .   T[2,2]=5; T[4,3]=1; .   T[3,1]=6; T[4,4]=4. .   T[3,2]=3; C[n,n]:=T[n,n];    T[3,3]=4; 2 5 3  4 5  6  1  4 T:
Implementarea programului: Pentru a tipari numerele luate  樽n calcul se folosete o matrice numit  drum  樽n care pentru fiecare  i,j  se ob釘ine coloana 樽n care se gasete succesorul lui T [i,j]; n-num rul de linii ; t,c, drum -de tip matrice;
Programul program triunghi; type matrice=array[1..10,1..10]of integer; var t,c,drum:matrice; i,j:integer; Begin write(n=);readln(n); for i:=1 to n do for j:=1 to I do begin write(t[,i,,,j,]=);readln(t[i,j]);end; for j:=1 to n do c[n,j]:=t[n,j]; for i:= n-1 downto 1 do begin for j:=1 to I do  if c[i+1,j]<c[i+1,j+1] then begin
c[i,j]:=t[i,j]+c[i+1,j+1]; drum[i,j]:=j+1;end else begin c[i,j]:=t[i,j]+c[i+1,j]; drum[i,j]:=j;end;end; writeln(suma maxima este,c[1,1]); i:=1;j:=1; while i<=n do begin writeln(t[i,j]); j:= drum[i,j]; i:=i+1;end; readln; End.

More Related Content

What's hot (8)

Metoda trieii..alina
Metoda trieii..alinaMetoda trieii..alina
Metoda trieii..alina
Balan Veronica
1+1=2
1+1=21+1=2
1+1=2
Gurguta
Integrare numeric
Integrare numericIntegrare numeric
Integrare numeric
Balan Veronica
E d informatica_2020_sp_mi_c_var_test_01
E d informatica_2020_sp_mi_c_var_test_01E d informatica_2020_sp_mi_c_var_test_01
E d informatica_2020_sp_mi_c_var_test_01
Ovidiu Dumitrescu
Met. bisectiei
Met. bisectieiMet. bisectiei
Met. bisectiei
stainless1

Viewers also liked (16)

Ilona tuotanto innostava ty旦yhteis旦
Ilona tuotanto innostava ty旦yhteis旦Ilona tuotanto innostava ty旦yhteis旦
Ilona tuotanto innostava ty旦yhteis旦
taijau
AIA Industries Brochure
AIA Industries BrochureAIA Industries Brochure
AIA Industries Brochure
Denise J. Dewberry
Portafolio tema 1Portafolio tema 1
Portafolio tema 1
Mario Alberto Rodriguez Padilla
Las TIC's en la Tutor鱈aLas TIC's en la Tutor鱈a
Las TIC's en la Tutor鱈a
Mario Alberto Rodriguez Padilla
Good practice catalogue
Good practice catalogueGood practice catalogue
Good practice catalogue
Dia Diana
2010 tecenfermeriaespecial2010 tecenfermeriaespecial
2010 tecenfermeriaespecial
luis carrillo huaiqui
John Mitchell Skanska Low Carbon Business Breakfast Investment in the West 19...
John Mitchell Skanska Low Carbon Business Breakfast Investment in the West 19...John Mitchell Skanska Low Carbon Business Breakfast Investment in the West 19...
John Mitchell Skanska Low Carbon Business Breakfast Investment in the West 19...
Matt Tudge
DecoBike
DecoBikeDecoBike
DecoBike
C Reese
Deco Celeb Friends
Deco Celeb FriendsDeco Celeb Friends
Deco Celeb Friends
C Reese
Evidencia electronicaEvidencia electronica
Evidencia electronica
Alejandro Mendoza G
Kuntoutuksen kehitt辰minen ja sote-uudistus - Kuntoutuss辰辰ti旦n ja Varman toteu...
Kuntoutuksen kehitt辰minen ja sote-uudistus - Kuntoutuss辰辰ti旦n ja Varman toteu...Kuntoutuksen kehitt辰minen ja sote-uudistus - Kuntoutuss辰辰ti旦n ja Varman toteu...
Kuntoutuksen kehitt辰minen ja sote-uudistus - Kuntoutuss辰辰ti旦n ja Varman toteu...
Kuntoutuss辰辰ti旦 (Rehabilitation Foundation)
La Tutor鱈a un encuentro con la ArquitecturaLa Tutor鱈a un encuentro con la Arquitectura
La Tutor鱈a un encuentro con la Arquitectura
Mario Alberto Rodriguez Padilla
亠从仍舒仄仆亠 于仂亰仄仂亢仆仂亳 仆舒 亟亠仍仂于仂仄 仗仂舒仍亠 capital.ua
亠从仍舒仄仆亠 于仂亰仄仂亢仆仂亳 仆舒 亟亠仍仂于仂仄 仗仂舒仍亠 capital.ua 亠从仍舒仄仆亠 于仂亰仄仂亢仆仂亳 仆舒 亟亠仍仂于仂仄 仗仂舒仍亠 capital.ua
亠从仍舒仄仆亠 于仂亰仄仂亢仆仂亳 仆舒 亟亠仍仂于仂仄 仗仂舒仍亠 capital.ua
capitalua
亠亰亠仆舒亳 亠亰ミ斜 仗仂亠从 弍ム仂于 仍亳亟亠舒 仆舒亳亳.
亠亰亠仆舒亳 亠亰ミ斜 仗仂亠从 弍ム仂于 仍亳亟亠舒 仆舒亳亳.亠亰亠仆舒亳 亠亰ミ斜 仗仂亠从 弍ム仂于 仍亳亟亠舒 仆舒亳亳.
亠亰亠仆舒亳 亠亰ミ斜 仗仂亠从 弍ム仂于 仍亳亟亠舒 仆舒亳亳.
仍亠从舒仆亟 弌仂于亶
Flow leadership serious games master class by buzady.pptx
Flow leadership serious games master class by buzady.pptxFlow leadership serious games master class by buzady.pptx
Flow leadership serious games master class by buzady.pptx
Zoltan Buzady
亳仄亠 仗仂仆仂从仂亞仂 仗舒从亠舒
亳仄亠 仗仂仆仂从仂亞仂 仗舒从亠舒亳仄亠 仗仂仆仂从仂亞仂 仗舒从亠舒
亳仄亠 仗仂仆仂从仂亞仂 仗舒从亠舒
Ekaterina Ilinskaya
Ilona tuotanto innostava ty旦yhteis旦
Ilona tuotanto innostava ty旦yhteis旦Ilona tuotanto innostava ty旦yhteis旦
Ilona tuotanto innostava ty旦yhteis旦
taijau
Las TIC's en la Tutor鱈aLas TIC's en la Tutor鱈a
Las TIC's en la Tutor鱈a
Mario Alberto Rodriguez Padilla
Good practice catalogue
Good practice catalogueGood practice catalogue
Good practice catalogue
Dia Diana
2010 tecenfermeriaespecial2010 tecenfermeriaespecial
2010 tecenfermeriaespecial
luis carrillo huaiqui
John Mitchell Skanska Low Carbon Business Breakfast Investment in the West 19...
John Mitchell Skanska Low Carbon Business Breakfast Investment in the West 19...John Mitchell Skanska Low Carbon Business Breakfast Investment in the West 19...
John Mitchell Skanska Low Carbon Business Breakfast Investment in the West 19...
Matt Tudge
DecoBike
DecoBikeDecoBike
DecoBike
C Reese
Deco Celeb Friends
Deco Celeb FriendsDeco Celeb Friends
Deco Celeb Friends
C Reese
Evidencia electronicaEvidencia electronica
Evidencia electronica
Alejandro Mendoza G
La Tutor鱈a un encuentro con la ArquitecturaLa Tutor鱈a un encuentro con la Arquitectura
La Tutor鱈a un encuentro con la Arquitectura
Mario Alberto Rodriguez Padilla
亠从仍舒仄仆亠 于仂亰仄仂亢仆仂亳 仆舒 亟亠仍仂于仂仄 仗仂舒仍亠 capital.ua
亠从仍舒仄仆亠 于仂亰仄仂亢仆仂亳 仆舒 亟亠仍仂于仂仄 仗仂舒仍亠 capital.ua 亠从仍舒仄仆亠 于仂亰仄仂亢仆仂亳 仆舒 亟亠仍仂于仂仄 仗仂舒仍亠 capital.ua
亠从仍舒仄仆亠 于仂亰仄仂亢仆仂亳 仆舒 亟亠仍仂于仂仄 仗仂舒仍亠 capital.ua
capitalua
亠亰亠仆舒亳 亠亰ミ斜 仗仂亠从 弍ム仂于 仍亳亟亠舒 仆舒亳亳.
亠亰亠仆舒亳 亠亰ミ斜 仗仂亠从 弍ム仂于 仍亳亟亠舒 仆舒亳亳.亠亰亠仆舒亳 亠亰ミ斜 仗仂亠从 弍ム仂于 仍亳亟亠舒 仆舒亳亳.
亠亰亠仆舒亳 亠亰ミ斜 仗仂亠从 弍ム仂于 仍亳亟亠舒 仆舒亳亳.
仍亠从舒仆亟 弌仂于亶
Flow leadership serious games master class by buzady.pptx
Flow leadership serious games master class by buzady.pptxFlow leadership serious games master class by buzady.pptx
Flow leadership serious games master class by buzady.pptx
Zoltan Buzady
亳仄亠 仗仂仆仂从仂亞仂 仗舒从亠舒
亳仄亠 仗仂仆仂从仂亞仂 仗舒从亠舒亳仄亠 仗仂仆仂从仂亞仂 仗舒从亠舒
亳仄亠 仗仂仆仂从仂亞仂 仗舒从亠舒
Ekaterina Ilinskaya

Triunghi

  • 1. Elev: Sima Marcel Cls a XI-a B
  • 2. Enuntul problemei Se consider un triunghi de numere naturale format din n linii. Prima linie con釘ine un numr,a doua dou numere, ... ,iar ultima,n numere naturale. Cu ajutorul acestui triunghi se pot forma sume de numere naturale 樽n felul urmtor: Se pornete cu numrul de pe linia 1; Succesorul unui numr se afl pe linia urmatoare plasat sub el(aceeai coloan) sau pe diagonal la dreapt(coloana crete cu 1);
  • 3. Pentru linia i pentru i<n se obtine astfel: C[i,j]=max{T[i,j]+C[i+1,j],T[i,j]+ +C[i+1,j+1]} i:=1,n-1; j:=1,i;
  • 4. T: 2 3 3 5 5 6 6 4 4 1 5 6 1 4 12 9 9 9 8 7 C: 6 6 6 + + + + + + 5 = = = = = = 11 11 12 < < < < 3 3 6 1 4 > 4 3 3 3 4 4 4 + + + + + 1 = = = = = 5 5 8 6 6 6 9 > 5 5 3 4 8 8 9 9 2 2 + = 3 5 5 5 7 12 8 9 9 9 7
  • 5. 2 3 3 5 5 6 6 4 4 1 T: 5 6 1 4 C: 12 9 9 6 6 6 + + + + 5 = = = = 11 11 12 < 3 3 6 1 4 > 4 8 + = = < 4 4 4 + 1 5 5 8 12 + + + + + + 5 = = = = = = 17 3 3 9 12 15 15 12 5 9 8 14 14 13 13 > > 2 2 15 14 17 16 16 > 12 9 8 15 14 17
  • 6. Algoritmul Pentru etapa i se trateaz linia i a triunghiului. Fie un ir de n numere care respect condi釘iile prolemei i care formeaz suma maxim, de aici considerm numrul care a fost preluat de pe linia i;vom forma un triunghi de la baz la v但rf cu sumele maxime care se pot forma cu fiecare numr.ntr-o matrice T citim t riunghiul de numere si 樽ntr-o matrice C vom avea urmtoarele rela釘ii:
  • 7. C [n,1]:=T[n,1]; T[1,1]=2; T[4,1]=5; C[n,2]:=T[n,2]; T[2,1]=3; T[4,2]=6; . T[2,2]=5; T[4,3]=1; . T[3,1]=6; T[4,4]=4. . T[3,2]=3; C[n,n]:=T[n,n]; T[3,3]=4; 2 5 3 4 5 6 1 4 T:
  • 8. Implementarea programului: Pentru a tipari numerele luate 樽n calcul se folosete o matrice numit drum 樽n care pentru fiecare i,j se ob釘ine coloana 樽n care se gasete succesorul lui T [i,j]; n-num rul de linii ; t,c, drum -de tip matrice;
  • 9. Programul program triunghi; type matrice=array[1..10,1..10]of integer; var t,c,drum:matrice; i,j:integer; Begin write(n=);readln(n); for i:=1 to n do for j:=1 to I do begin write(t[,i,,,j,]=);readln(t[i,j]);end; for j:=1 to n do c[n,j]:=t[n,j]; for i:= n-1 downto 1 do begin for j:=1 to I do if c[i+1,j]<c[i+1,j+1] then begin
  • 10. c[i,j]:=t[i,j]+c[i+1,j+1]; drum[i,j]:=j+1;end else begin c[i,j]:=t[i,j]+c[i+1,j]; drum[i,j]:=j;end;end; writeln(suma maxima este,c[1,1]); i:=1;j:=1; while i<=n do begin writeln(t[i,j]); j:= drum[i,j]; i:=i+1;end; readln; End.