Advertisement
yuawn

algo2017_week7_knapsack

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