-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy path1034.cpp
More file actions
25 lines (25 loc) · 719 Bytes
/
Copy path1034.cpp
File metadata and controls
25 lines (25 loc) · 719 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
// Ivan Carvalho
// Solution to https://www.beecrowd.com.br/judge/problems/view/1034
#include <algorithm>
#include <cstdio>
#include <cstring>
#define LIMIT 9999999
using namespace std;
int tab[1001000], moedas[25];
int main() {
int casos, valor, numero;
scanf("%d", &casos);
while (casos--) {
memset(tab, LIMIT, sizeof(tab));
scanf("%d %d", &numero, &valor);
for (int i = 0; i < numero; i++) scanf("%d", &moedas[i]);
tab[0] = 0;
for (int i = 0; i < valor; i++) {
for (int j = 0; j < numero; j++) {
tab[i + moedas[j]] = min(tab[i + moedas[j]], tab[i] + 1);
}
}
printf("%d\n", tab[valor]);
}
return 0;
}