-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirst.java
More file actions
67 lines (57 loc) · 1.58 KB
/
first.java
File metadata and controls
67 lines (57 loc) · 1.58 KB
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
package other;
import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class first {
public static List<List<Integer>> result=new ArrayList<>();
public static Map<Integer,Integer> map=new HashMap<>();
public static void main(String[] args) {
int[] s=new int[]{2,3,4,5,6,7};
map.put(6,9);
map.put(7,8);
map.put(3,7);
map.put(5,5);
map.put(4,4);
map.put(2,1);
Scanner scanner=new Scanner(System.in);
int num=scanner.nextInt();
int k=scanner.nextInt();
List<Integer> list=new ArrayList<>();
dfs(num,k,s,list);
Set<List> set=new HashSet<>(result);
System.out.println(set);
int Min=Integer.MIN_VALUE;
for(List l:set){
if(setSum(l)>Min)
Min=setSum(l);
}
System.out.println(Min);
}
public static void dfs(int num,int k,int []s,List<Integer> list){
if(k==0){
if(sum(list)==num){
result.add(new ArrayList<>(list));
return;
}else return;
}
for(int i:s){
list.add(i);
dfs(num,k-1,s,list);
list.remove(list.size()-1);
}
}
public static int sum(List<Integer> list){
int sum=0;
for(int i:list){
sum=sum+i;
}
return sum;
}
public static int setSum(List<Integer> list){
int a[]=new int[6];
for(int i:list){
}
return 1;
}
}