-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCHEFFA.txt
More file actions
53 lines (50 loc) · 1.31 KB
/
CHEFFA.txt
File metadata and controls
53 lines (50 loc) · 1.31 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
//https://www.codechef.com/problems/CHEFFA
//author: Pravash Ranjan Nayak
import java.util.*;
class Solution
{
public static void main(String args[])
{
Scanner ob=new Scanner(System.in);
int t=ob.nextInt();
while(t-->0){
int n = ob.nextInt();
int a[]=new int[102];
//ArrayList<Integer> a=new ArrayList<>();
for(int i=0;i<n;i++)
a[i]=ob.nextInt();
//System.out.println(a);
HashSet<String> set=new HashSet<>();
solve(a,n,set);
System.out.println(set.size());
}
}
public static void solve(int a[] ,int n,HashSet<String>set)
{
String str=Arrays.toString(a);
if(set.contains(str))
return;
set.add(str);
//print(a,n);
for(int i=0;i<n-1;i++)
{
if(a[i]>0 && a[i+1]>0)
{
int b[]=a.clone();
b[i]-=1;
b[i+1]-=1;
b[i+2]+=1;
if(i+2==n)
solve(b,n+1,set);
else
solve(b,n,set);
}
}
}
public static void print(int a[],int n)
{
for(int i=0;i<n;i++)
System.out.print(a[i]+" ");
System.out.println();
}
}