Advertisement
mirekw

Klaudia

Oct 25th, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6.  
  7. int oblicz(int tab[],int poziom,bool * formula)
  8. {
  9.     int wynik=0;
  10.     for(int i=0;i<poziom;i++)
  11.         if(formula[i]==true)
  12.             wynik+=tab[i];
  13.     return wynik;
  14. }
  15.  
  16. void sprawdz(int poziom,int stopnie[], int koszt[], bool* formula,int m,int &suma){
  17.  
  18.    
  19.     int cena=oblicz(koszt,poziom,formula);
  20.  
  21.     if(oblicz(stopnie,poziom,formula) == 0 && cena!=0  && suma>cena)
  22.            suma = cena;
  23.  
  24.       formula[poziom] = false;
  25.  
  26.        if(poziom<m && cena<suma)
  27.            sprawdz(poziom+1,stopnie,koszt,formula,m,suma);
  28.  
  29.       formula[poziom] = true;
  30.  
  31.        if(poziom<m && cena<suma)
  32.            sprawdz(poziom+1,stopnie,koszt,formula,m,suma);
  33.  
  34.  
  35. }
  36. int main()
  37. {
  38.     int n;
  39.     int m;    
  40.     int suma;
  41.     cin>>n;
  42.     for(int i=0;i<n;i++){
  43.         cin>>m;
  44.     int stopnie[m];
  45.         int koszt[m];
  46.         bool formula[m];
  47.         suma=10001;
  48.         for(int j=0;j<m;j++){
  49.             cin>>stopnie[j];
  50.             cin>>koszt[j];
  51.             formula[j]=true;
  52.         }
  53.     sprawdz(0,stopnie,koszt,formula,m,suma);
  54.  
  55.       if(suma != 10001)
  56.          cout<<suma<<endl;
  57.       else cout<<"DEPRESJA"<<endl;
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement