Created
May 12, 2015 15:48
-
-
Save igaryhe/855b6a5134ca5bbabde1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
#define MAX 2000 | |
using namespace std; | |
int main() { | |
int t; | |
cin >> t; | |
for (int i = 0; i != t; ++i) { | |
int n, k; | |
vector<int> v; | |
cin >> n >> k; | |
for (int j = 0; j != n; ++j) { | |
int a; | |
cin >> a; | |
v.push_back(a); | |
} | |
int dp[MAX + 1] = {0}; | |
for (int i = 0; i < n; ++i) | |
for (int j = 0; j <= k; ++j) | |
if (j >= v[i]) dp[j] = max(dp[j], dp[j - v[i]] + v[i]); | |
cout << dp[k] << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment