We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4b15ba5 commit 861e165Copy full SHA for 861e165
Dynamic Programming/BOJ2294.cpp
@@ -0,0 +1,38 @@
1
+#include<iostream>
2
+#include<vector>
3
+#include<algorithm>
4
+using namespace std;
5
+
6
+vector<int> coins;
7
+int n,k;
8
+int dp[10001];
9
10
+void input() {
11
+ cin>>n>>k;
12
+ coins.resize(n);
13
+ for(int i=0; i<n; i++) cin>>coins[i];
14
+}
15
16
+void solve() {
17
+ input();
18
+ sort(coins.begin(), coins.end());
19
+ fill(dp,dp+10001,2e9);
20
+ for(int i=0; i<n; i++) {
21
+ int now = coins[i];
22
+ if(now>k) break;
23
+ dp[now] = 1;
24
+ for(int p=now+1; p<=k; p++) {
25
+ dp[p] = min(1+dp[p-now],dp[p]);
26
+ }
27
28
+ cout<<(dp[k]>=2e9 ? -1 : dp[k]);
29
30
31
+int main() {
32
+ cin.tie(nullptr);
33
+ cout.tie(nullptr);
34
+ ios_base::sync_with_stdio(false);
35
36
+ solve();
37
+ return 0;
38
0 commit comments