-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeu-troco2.cpp
78 lines (62 loc) · 1.33 KB
/
meu-troco2.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// problem: https://neps.academy/lesson/186
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <string.h> // memset
#include <algorithm> // lower_bound
using namespace std;
#define fs first
#define sd second
#define pb push_back
#define MAXN 120000
const int INF = 0x3f3f3f3f;
int dp[MAXN], n, aux;
vector<int> coins;
// input:
// 4 7
// 1 3 4 5
// output: 1
// 2 10
// 1 5
// output: 1
// 2 10
// 3 3
// output: N
// return:
// 1 : it is possible form the value with the coins
// 0 : it is not posible form the value the coins
// return
// x :the min number of coins to form the value
// INF: It's not possible form the value
// complexity O(n*value);
int change_2(int value) {
if(value == 0)
return 0;
if(value < 0)
return INF;
if(dp[value] != -1) {
return dp[value];
}
int ans = INF;
for(int i = 0; i < n; ++i) {
ans = min(change_2(value - coins[i]), ans);
}
return dp[value] = ans + 1;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int value;
cin >> n >> value;
for(int i = 0; i < n; ++i) {
cin >> aux;
coins.pb(aux);
}
memset(dp, -1, sizeof dp);
string s = (change_2(value) < 10)? "S\n": "N\n";
cout << s;
return 0;
}