SHARE
TWEET

ASD Pb 24 tija

madalinaradu May 26th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ** p45 tija programare dinamica */
  2. #include<stdio.h>
  3. #include<conio.h>
  4. #include<stdbool.h>
  5. #include<iostream>
  6. using namespace std;
  7. #define MAX 9
  8.  
  9. int max(int a,int b) {
  10.     return(a>b)?a:b;
  11. }
  12. int main() {
  13.     int n=8;
  14.     int pret[] = {0, 1, 5, 8, 9, 10, 17, 17, 20};
  15.     int rez[MAX+1];///tabloul in care se calculeaza profitul maxim dupa taierea pana la 1,2,...8 cm
  16.     rez[0]=0;
  17.  
  18.     for(int i=1; i<=MAX; i++) {
  19.         int maxim=-1;//maximul pt fiecare dimensiune de tija
  20.         for(int j=1; j<=i; j++) {
  21.             maxim=max((pret[j]+rez[i-j]),maxim);
  22.         }
  23.         rez[i]=maxim;
  24.     }
  25.     cout<<"valoarea maxima este: "<<rez[n]<<endl;
  26.     return 0;
  27. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top