forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path10503.cpp
85 lines (83 loc) · 1.1 KB
/
10503.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
#include <bits/stdc++.h>
using namespace std;
/*
The dominoes solitaire
10503
*/
int space, spices, sp;
int sr, sc, tr, tc;
struct ss
{
int r, c;
int ind;
} point[30];
char fg[40];
int recur(int r, int c, int index, int level)
{
int i, x, y;
if (level == space)
{
if (c == tr)
{
return 1;
}
return 0;
}
fg[index] = 1;
for (i = 0; i < sp; i++)
{
if (fg[point[i].ind])
{
continue;
}
if (c == point[i].r)
if (recur(point[i].r, point[i].c, point[i].ind, level + 1))
{
return 1;
}
}
fg[index] = 0;
return 0;
}
void Cal()
{
int x;
x = recur(sr, sc, 30, 0);
if (x)
{
puts("YES");
}
else
{
puts("NO");
}
for (x = 0; x < 35; x++)
{
fg[x] = 0;
}
}
int main()
{
int i;
while (scanf("%d", &space), space)
{
scanf("%d", &spices);
scanf("%d%d", &sr, &sc);
scanf("%d%d", &tr, &tc);
sp = spices;
for (i = 0; i < spices; i++)
{
scanf("%d%d", &point[i].r, &point[i].c);
point[i].ind = i;
if (point[i].r == point[i].c)
{
continue;
}
point[sp].r = point[i].c;
point[sp].c = point[i].r;
point[sp++].ind = i;
}
Cal();
}
return 0;
}