Advertisement
apl-mhd

uva wedding shoping 11450

Aug 12th, 2017
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <vector>
  5.  
  6.  
  7. using namespace std;
  8.  
  9.  
  10. int main(int argc, char **argv)
  11. {/*
  12.     8 6 4
  13. 2 5 10
  14. 4 1 3 3 7
  15. 4 50 14 23 8
  16.     */
  17.     int totalAmount = 100;
  18.     vector<int>garment[4];
  19.    
  20.     garment[0].push_back(6);
  21.     garment[0].push_back(4);
  22.     garment[0].push_back(8);
  23.    
  24.     garment[1].push_back(5);
  25.     garment[1].push_back(10);
  26.    
  27.     garment[2].push_back(1);
  28.     garment[2].push_back(3);
  29.     garment[2].push_back(3);
  30.     garment[2].push_back(7);
  31.    
  32.     garment[3].push_back(50);
  33.     garment[3].push_back(14);
  34.     garment[3].push_back(23);
  35.     garment[3].push_back(8);
  36.    
  37.    
  38.    
  39.     for(int i=0; i<3; i++){
  40.        
  41.         int secondSize = garment[i+1].size();
  42.        
  43.         for(int j=0; j<garment[i].size(); j++){
  44.                 int x = garment[i][j];
  45.            
  46.             for(int k=0; k<secondSize; k++){
  47.                
  48.                 int y = garment[i+1][k];
  49.                
  50.                 if (x+y <= totalAmount)
  51.                     garment[i+1].push_back(x+y);
  52.                
  53.                
  54.                 }
  55.            
  56.                
  57.             }
  58.            
  59.             garment[i+1].erase(garment[i+1].begin(),garment[i+1].begin()+secondSize);
  60.        
  61.         }
  62.        
  63.        
  64.     //for(int i=0; i<4; i++){
  65.        
  66.         sort(garment[3].begin(), garment[3].end());
  67.        
  68.         for (int j=0; j<garment[3].size(); j++){
  69.            
  70.             cout<<garment[3][j]<<" ";
  71.             }
  72.            
  73.         cout<<endl;
  74.        
  75.         //}
  76.    
  77.     return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement