-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathneps509.cpp
More file actions
40 lines (30 loc) · 694 Bytes
/
Copy pathneps509.cpp
File metadata and controls
40 lines (30 loc) · 694 Bytes
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
/*
* Contest : OBI 2013 - Fase 2
* Problem : Troco
* Link : https://neps.academy/br/exercise/509
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fastio ios::sync_with_stdio(0); cin.tie(0);
int v, m;
vector<int> moedas;
bool coin_change(int soma) {
int n = moedas.size();
vector<bool> dp(soma + 1, false);
dp[0] = true; // Caso base.
for (int i = 0; i < n; ++i) {
for (int j = soma; j >= moedas[i]; --j) {
if (dp[j - moedas[i]]) dp[j] = true;
}
}
return dp[soma];
}
int main() {
fastio
cin >> v >> m;
moedas.resize(m);
for (auto &i : moedas) cin >> i;
cout << (coin_change(v) ? "S" : "N") << "\n";
return 0;
}