-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp31.java
More file actions
27 lines (22 loc) · 698 Bytes
/
p31.java
File metadata and controls
27 lines (22 loc) · 698 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
//wasnt this problem on every contest ever?
import java.util.*;
public class p31 {
public static void main(String[] args){
List<Integer> l = new LinkedList(Arrays.asList(1,2,5,10,20,50,100,200));
System.out.println(what(l,200));
}
//slow :\
//works though
private static int what(List<Integer> use, int target){
if (target < 0){return 0;}
if (target == 0){return 1;}
int out= 0;
int size= use.size();
for (int i = size -1; i >= 0; i--){
List<Integer> copy = new LinkedList<Integer>(use);
out += what(copy, target - use.get(i));
use.remove(i);
}
return out;
}
}