-
Notifications
You must be signed in to change notification settings - Fork 34
/
1018-Brush-4.cpp
145 lines (103 loc) · 1.86 KB
/
1018-Brush-4.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#define set(x, i) (x | (1 << i))
#define check(x, i) (x & (1 << i))
using namespace std;
enum CONST {N = 16};
typedef struct node {
int x;
int y;
} node;
int n;
int collinear[N+3][N+3];
int dp[1 << N+2];
node a[N + 5];
int cal(int state)
{
int count;
count = 0;
for (int i = 1; i <= n; i++)
if(check(state, i))
count++;
return count;
}
int explore(int status)
{
int count;
int temp;
int mini;
mini = INT_MAX;
if(dp[status] != -1) {
return dp[status];
}
count = cal(status);
if(count == n-1) {
return 1;
}
if(count == n) {
return 0;
}
for (int i = 1; i <= n; i++) {
if(check(status,i) == 0) {
for (int j = i+1; j <= n; j++) {
if(check(status, j) == 0) {
temp = set(status, i);
temp = set(temp, j);
temp = temp | collinear[i][j];
mini = min(mini, explore(temp));
}
}
break;
}
}
return dp[status] = 1 + mini;
}
bool is_collinear(int i, int j, int k)
{
int x1;
int y1;
int x2;
int y2;
int x3;
int y3;
x1 = a[i].x;
y1 = a[i].y;
x2 = a[j].x;
y2 = a[j].y;
x3 = a[k].x;
y3 = a[k].y;
return (y2 - y1) * (x3 - x2) == (x2 - x1) * (y3 - y2);
}
void calculate_collinear_points()
{
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
for (int k = 1; k <= n; k++) {
if(i != k and j != k and is_collinear(i, j, k)) {
collinear[i][j] = set(collinear[i][j], k);
collinear[j][i] = set(collinear[j][i], k);
}
}
}
}
}
int main()
{
int t;
node temp;
scanf("%d", &t);
for(int cs = 1; cs <= t; cs++) {
scanf("%d", &n);
memset(collinear, 0, sizeof collinear);
memset(dp, -1, sizeof dp);
for (int i = 1; i <= n; i++) {
scanf("%d", &temp.x);
scanf("%d", &temp.y);
a[i] = temp;
}
calculate_collinear_points();
printf("Case %d: %d\n", cs, explore(0));
}
}