Advertisement
yuawn

algo2017_week8_change

Nov 23rd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define pb push_back
  4. #define ALL(o) (o).begin(),(o).end()
  5. #define fo(n) for(int i=0;i<n;i++)
  6. #define fos(o,n) for(int i=o;i<=n;i++)
  7.  
  8.  
  9. int main(){
  10.     int T;
  11.    
  12.     cin >> T;
  13.    
  14.     while( T-- ){
  15.         int n , s;
  16.        
  17.         cin >> n >> s;
  18.        
  19.         int x[n] , c[s + 1];
  20.        
  21.         fo( n ) cin >> x[i];
  22.         fo( s + 1 ) c[i] = 1e9;
  23.         c[0] = 0;
  24.        
  25.         fo( n )
  26.             for( int j = x[i] ; j < s + 1 ; ++j )
  27.                 c[j] = min( c[j] , c[ j - x[i] ] + 1 );
  28.        
  29.        
  30.         cout << c[ s ] << endl;
  31.     }
  32.  
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement