-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11045.cpp
107 lines (103 loc) · 1.46 KB
/
11045.cpp
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
11045 - My T-shirt suits me
*/
#include<bits/stdc++.h>
using namespace std;
/*
(XXL, XL, L, M , S, or XS)
1 2 3 4 5 6
*/
const char ss[][4]= {"XXL","XL","L","M","S","XS"};
int graph[30][2];
int used[30];
bool flag;
int n,m,t;
int position(const char *str)
{
for(int i=0; i<6; i++)
{
if(strcmp(ss[i],str)==0)
{
return i;
}
}
}
void dfs(int idx)
{
if(flag)
return;
if(idx==m)
{
flag=true;
return;
}
if(used[graph[idx][0]]>0)
{
used[graph[idx][0]]--;
dfs(idx+1);
used[graph[idx][0]]++;
}
if(used[graph[idx][1]]>0)
{
used[graph[idx][1]]--;
dfs(idx+1);
used[graph[idx][1]]++;
}
}
int main()
{
cin>>t;
while(t--)
{
cin>>n>>m;
for(int i=0; i<m; i++)
{
char temp[4];
cin>>temp;
int idx = position(temp);
graph[i][0]=idx;
cin>>temp;
idx = position(temp);
graph[i][1]=idx;
}
n=n/6;
///available T-shirt
for(int i=0; i<6; i++)
{
used[i]=n;
}
flag=0;
dfs(0);
if(flag)
{
cout<<"YES"<<endl;
}
else
{
cout<<"NO"<<endl;
}
}
return 0;
}
/*
Sample Input
3
18 6
L XL
XL L
XXL XL
S XS
M S
M L
6 4
S XL
L S
L XL
L XL
6 1
L M
Sample Output
YES
NO
YES
*/