Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define N 101
- using namespace std;
- int n, m;
- int a[N], d[INF];
- const int INF = 10005;
- int main() {
- cin >> n >> m;
- for (int i = 1; i <= n; i++)
- cin >> a[i];
- for (int i = 1; i <= m; i++)
- d[i] = INF;
- sort(a + 1, a + n + 1);
- for (int i = 1; i <= n; i++) {
- for (int j = 0; j <= m; j++) {
- if(j - a[i] >= 0)
- d[j] = min(d[j], d[j - a[i]] + 1);
- }
- }
- if (d[m] != INF) cout << d[m];
- else cout << 0;
- }
- /**6 10
- 1 1 1 5 5 7*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement