File tree Expand file tree Collapse file tree 1 file changed +76
-0
lines changed Expand file tree Collapse file tree 1 file changed +76
-0
lines changed Original file line number Diff line number Diff line change 1+ #include < iostream>
2+ #include < cstring>
3+ #include < algorithm>
4+ #define MAXN 25
5+ using namespace std ;
6+
7+ int sticks[MAXN];
8+ bool visit[MAXN];
9+
10+ int side;
11+ int m,n;
12+ bool DFS (int sum,int number,int position)
13+ {
14+ if (number == 3 )
15+ return true ;
16+
17+ int sample = 0 ;
18+ for (int i = position; i<m; i++)
19+ {
20+ if ( visit[i] || sum + sticks[i] > side || sticks[i] ==sample) continue ;
21+ visit[i] = true ;
22+ if ( sum + sticks[i] == side)
23+ {
24+ if (DFS (0 ,number+1 ,0 ))return true ;
25+ else sample = sticks[i];
26+ }
27+ else
28+ {
29+ if (DFS (sum+sticks[i],number, i +1 ))return true ;
30+ else sample = sticks[i];
31+ }
32+ visit[i] = false ;
33+ }
34+ return false ;
35+ }
36+ int main ()
37+ {
38+ ios::sync_with_stdio (false );
39+ cin >> n;
40+ while (n--)
41+ {
42+ int length = 0 ;
43+ cin >> m;
44+ for (int i=0 ; i<m; i++)
45+ {
46+ cin >> sticks[i];
47+ length += sticks[i];
48+ }
49+ memset (visit,false ,sizeof (visit));
50+ if (length % 4 != 0 )
51+ {
52+ cout<< " no\n " ;
53+ continue ;
54+ }
55+ side = length / 4 ;
56+ sort (sticks,sticks+m,less<int >());
57+ if (sticks[0 ] > side)
58+ {
59+ cout<< " no\n " ;
60+ continue ;
61+ }
62+ if (DFS (0 ,0 ,0 ))
63+ {
64+ cout << " yes\n " ;
65+ }
66+ else
67+ {
68+ cout << " no\n " ;
69+ }
70+
71+
72+ }
73+
74+
75+ return 0 ;
76+ }
You can’t perform that action at this time.
0 commit comments