Advertisement
rdsedmundo

estatuas.cpp

Jul 16th, 2015
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. #define MAXN 125
  7. int N, M, v[MAXN];
  8.  
  9. int menor_maneira;
  10.  
  11. int calc = 0;
  12. void consegue(int obj, int value, int count) {
  13.  
  14.     if (value == M) {
  15.         menor_maneira = min(menor_maneira, count);
  16.         return;
  17.     }
  18.    
  19.     if (obj > N)
  20.         return;
  21.    
  22.     if (value > M)
  23.         return;
  24.    
  25.     cout << obj << " " << value << " " << count << endl;
  26.    
  27.     consegue(obj+1, value, count);
  28.    
  29.     for (int i = 1; (i*v[obj]+value) <= M; i++)
  30.         consegue(obj+1, i*v[obj]+value, count+i);
  31.        
  32. }
  33.  
  34. int main() {
  35.    
  36.     int t;
  37.     cin >> t;
  38.    
  39.     while (t--) {
  40.         int n, m;
  41.         cin >> n >> m;
  42.        
  43.         for (int i = 1; i <= n; i++)
  44.             cin >> v[i];
  45.        
  46.         menor_maneira = 1<<20;
  47.         N = n;
  48.         M = m;
  49.         consegue(1, 0, 0);
  50.        
  51.         cout << menor_maneira << endl;
  52.     }
  53.    
  54.     return 0;  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement