Programare+dinamica


 * Problema triunghiului: se da un triunghi cu n linii de numere. Exista un „pion calator” care pleaca din casuta cea mai de sus a triunghiului si care se poate deplasa fie pe verticala in jos, fie pe diagonala la dreapta. Sa se gaseasca succesiunea de pasi realizati de pion, astfel incat suma numerelor din casutele vizitate de pion sa fie maxima.


 * N piese de domino sunt aliniate pe un covor. Sa se extraga dintre acestea cat mai putine, astfel incat cele care raman sa formeze un sir care respecta regula acestui joc.

Ex: ** 1-2 ** 3-5 ** 2-7 ** 3-4 ** 7-3 **
 * Se dau n cuburi de diverse culori si laturi. Sa se afiseze cel mai lung turn care se poate construi astfel incat 2 cuburi alaturate sa aiba culori diferite si un cub sa se aseze doar pe unul mai mare decat el.


 * Problema rucsacului. Explicatii: [] pb.6

#include  #include  #include  using namespace std;  struct piesa { int st, dr;} x[100];  int n;  int z[100];  void citire  {  ifstream fin("date.in");  fin>>n;  for(int i=0;i fin>>x[i].st>>x[i].dr;  fin.close ; <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> } <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> int main <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> { <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> int i,j,max,y[100],maxt=0,pmax=-1; <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> citire ; <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> y[n-1]=1; <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> for(i=n-2;i>=0;i--) <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> { <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> max=0; <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> for(j=i+1;j<n;j++) <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> { <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> if(x[i].dr==x[j].st && y[j]>max) <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> { <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> max=y[j]; <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> } <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> } <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> y[i]=max+1; <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> if(maxt<max+1) <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> { <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> maxt=max+1; <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> pmax=i; <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> } <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> } <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> cout<<"Maxt="<<maxt <<" pmax= "<<pmax<<endl; <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> for(i=0;i<n;i++) <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> cout<<setw(3)<<x[i].st<<"-"<<x[i].dr; <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> cout<<endl; <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> for(j=0;j<n;j++) <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> cout<<setw(5)<<y[j]; <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> cout<<endl; <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> cout<<"se extrag "<<n-maxt<<" piese"<<endl; <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> maxt--; <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> z[pmax]=1; <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> for(i=0;i<n&&maxt;i++) <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> if(y[i]==maxt&& x[pmax].dr==x[i].st) <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> { <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> z[i]=1; <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> maxt--; <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> pmax=i; <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> } <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> for(i=0;i<n;i++) <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> if(z[i]==0) <span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> cout<<setw(3)<<x[i].st<<"-"<<x[i].dr;
 * Se da o multime de n numere naturale. Sa se imparta multimea in doua submultimi astfel incat sa se minimizeze |S1 –S2|, unde S1 si S2 sunt sumele elementelor celor 2 submultimi.

<span style="display: block; height: 1px; left: -40px; overflow: hidden; position: absolute; top: -25px; width: 1px;"> }