forked from nivedha-ravi/Code-and-Compile
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColors formation.java
More file actions
47 lines (45 loc) · 892 Bytes
/
Colors formation.java
File metadata and controls
47 lines (45 loc) · 892 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
41
42
43
44
45
46
47
/*
Example Input/Output 1:
Input:
5
1 5 3 2 4 2 5
Output: 2
Explanation:
Here X=2 and Y=5.
There are two ways to form the color 5 by mixing exactly 2 colors.
1 + 4 = 5
3 + 2 = 5
So 2 is printed as the output.
Example Input/Output 2:
Input:
8 6 4 2 5 8 7 3 1
3 15
Output: 6
*/
import java.util.*;
public class Hello {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int N=sc.nextInt();
int[] colors=new int[N];
for(int index=0;index<N;index++){
colors[index]=sc.nextInt();
}
int color=0;
int X=sc.nextInt();
int Y=sc.nextInt();
for(int ctr=1;ctr<=(1<<N);ctr++){
int count=0,sum=0;
for(int index=0;index<N;index++){
if((ctr & (1<<index))>0){
sum+=colors[index];
count++;
}
}
if(count==X && sum==Y){
color++;
}
}
System.out.println(color);
}
}