-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLittleelephant.cpp
More file actions
71 lines (67 loc) · 1.22 KB
/
Copy pathLittleelephant.cpp
File metadata and controls
71 lines (67 loc) · 1.22 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
67
68
69
70
71
#include<bits/stdc++.h>
using namespace std;
int total = 0;
int permute(int arr[],vector<int> arr2[],int depth,int count)
{
//cout<<"reached here";
//cout<<(depth);
if(depth == count+1)
{
total++;
//cout<<"Increased";
return 0;
}
//cout<<"arr2"<<arr2[depth].size()<<endl;
for(int i=0;i<arr2[depth].size();i++)
{
//cout<<"-->"<<arr2[depth][i];
if(arr[arr2[depth][i]]!=1)
{
//cout<<"selectd"<<arr2[depth][i]<<endl;
arr[arr2[depth][i]] = 1;
permute(arr,arr2,depth+1,count);
//cout<<"Returnde";
arr[arr2[depth][i]]=2;
}
}
return 0;
}
int main()
{
int t;
cin>>t;
while(t--)
{
::total = 0;
int arr[101];
memset(arr,0,101);
int count;
cin>>count;
vector<int>arr2[count+1];
int i =1;
char ch[50000];
gets(ch);
while(i<=count)
{
//cout<<"Input";
//cout<<"i"<<i<<endl;
gets(ch);
//cout<<"Inp done";
//puts(ch);
char *pat = strtok(ch," ");
while(pat!=NULL)
{
int j = atoi(pat);
//cout<<endl<<j<<endl;
pat = strtok(NULL," ");
arr2[i].push_back(j);
//arr[j]=2;
}
//cout<<"done";
i++;
}
int perm[count+1];
permute(arr,arr2,1,count);
cout<< ::total<<endl;
}
}