-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBANKNOTES.cpp
56 lines (49 loc) · 1.12 KB
/
BANKNOTES.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long long b[n],c[n];
long long k,tot = 0;
for (int i = 0; i < n; i++)
cin >> b[i];
for (int i = 0; i < n; i++) {
cin >> c[i];
tot += c[i];
}
cin >> k;
long long val[tot+1];
val[0] = 0;
long long inc = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < c[i]; j++) {
val[inc] = b[i];
inc++;
}
}
long long V[tot+2][k+1];
for (int i = 0; i < k+1; i++)
V[0][i] = 10000;
for (int j = 0; j < tot+2; j++)
V[j][0] = 0;
for (int i = 1; i < tot+2; i++)
for (int j = 1; j < k+1; j++)
V[i][j] = 10000;
for (int i = 1; i <= tot+2; i++)
for (int j = 1; j <= k+1; j++){
if (val[i-1] > j)
V[i][j] = V[i-1][j];
else
V[i][j] = min(V[i-1][j],1+V[i-1][j-val[i-1]]);
}
/*
for (int i = 0; i < tot+2; i++) {
for (int j = 0; j < k+1; j++) {
cout << V[i][j] << " ";
}
cout << endl;
}
*/
cout << V[tot+1][k];
return 0;
}