-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCCC'00S4.java
More file actions
40 lines (35 loc) · 985 Bytes
/
Copy pathCCC'00S4.java
File metadata and controls
40 lines (35 loc) · 985 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
import java.util.Scanner;
import java.lang.Math;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int target = sc.nextInt();
int numClubs = sc.nextInt();
int[] clubs = new int[numClubs];
int[] turns = new int[target+1];
Arrays.fill(turns, Integer.MAX_VALUE);
for (int x = 0; x < numClubs; x++){
clubs[x] = sc.nextInt();
if (check(clubs[x], target))
turns[clubs[x]] = 1;
}
for (int x = 0; x <= target; x++) {
for (int y = 0; y < numClubs; y++){
if ( check(x + clubs[y], target) && turns[x+clubs[y]] > turns[x])
turns[x + clubs[y]] = turns[x] + 1;
}
}
if (turns[target] != Integer.MAX_VALUE) {
System.out.println("Roberta wins in " + turns[target] + " strokes.");
} else {
System.out.println("Roberta acknowledges defeat.");
}
}
static boolean check (int n, int target) {
if (n < target+1 && n > 0) {
return true;
}
return false;
}
}