Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define fast_read; ios::sync_with_stdio(0);cin.tie(0);
- #define INF INT_MAX
- using namespace std;
- int n,a[101],x,ans[101];
- int main() {
- fast_read;
- cin>>n;
- for (int i = 1;i<=n;i++)cin>>a[i];
- cin>>x;
- ans[0] = 0;
- for (int i = 1;i<=x;i++) {
- ans[i] = INF;
- for (int j = 1;j<=n;j++) {
- if (i - a[j] >= 0) ans[i] = min(ans[i],ans[i - a[j]] + 1);
- }
- }
- cout<<ans[x]<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment