-
Notifications
You must be signed in to change notification settings - Fork 0
/
Number38.java
55 lines (54 loc) · 1.29 KB
/
Number38.java
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
import java.util.*;
public class Number38 {
static ArrayList<Integer> nm=new ArrayList<>();
static ArrayList<Integer> kk=new ArrayList<>();
static ArrayList<String> k=new ArrayList<>();
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n,i,f=0;
System.out.println("Enter the size of the array");
n=sc.nextInt();
int a[]=new int[n];
System.out.println("Enter "+n+" numbers");
for(i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
task(a);
for(i=1;i<nm.size();i++)
{
if(nm.get(i)%n==0)
{
System.out.println(kk.get(i));
System.out.println(k.get(i));
f=1;
break;
}
}
if(f==0)
System.out.println("No such subsequences found");
}
static void task(int a[])
{
int s=0,i,j,c=0;
String p="";
for (i=0;i<1<<a.length;i++)
{
s=0;
c=0;
p="";
for (j=0;j<a.length;j++)
{
if((i&(1<<j))>0)
{
s=s+a[j];
c++;
p=p+a[j];
}
}
nm.add(s);
kk.add(c);
k.add(p);
}
}
}