题目大意: 有n个灰尘, 给出坐标, 吸尘器每次可以清理一条线上的全部灰尘, 问最少需要画几条线将全部灰尘覆盖。
一开始理解错题意了以为下一次画线的起点必须是上一次的终点Orz 后来发现每一次都可以随意确定起点终点。 所以直接就更简单了, 01代表这个灰尘是否还存在。
由于画线是任意的, 所以可以随意取一个点 然后枚举另一个点然后用这两个点画线(这里的随意具体到代码就是找到该状态的第一个1)。
实现起来并不难,代码如下:
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <string>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
#define ls id<<1,l,mid
#define rs id<<1|1,mid+1,r
#define OFF(x) memset(x,-1,sizeof x)
#define CLR(x) memset(x,0,sizeof x)
#define MEM(x) memset(x,0x3f,sizeof x)
typedef long long ll ;
typedef pair<int,int> pii ;
const int maxn = 1e5+50 ;
const int inf = 0x3f3f3f3f ;
const int MOD = 1e9+7 ;
int T,n,is_line[20][20];
int dp[1<<16];
struct pnt{
int x,y;
} p[20];
bool check(int a,int b,int c) {
return (p[b].x - p[a].x) * (p[c].y - p[b].y) == (p[c].x - p[b].x) * (p[b].y - p[a].y) ;
}
void init(){
CLR(is_line);
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
for (int k = 0; k < n; k++) {
if (check(i,j,k)) is_line[i][j] |= 1 << k ;
}
}
}
}
int dfs(int s) {
int cnt = __builtin_popcount(s);
if (cnt == 0) return 0;
if (cnt <= 2) return 1;
int &res = dp[s];
if (res != inf) return res;
// cout << id << "\n" ;
int i = 0;
while ((s >> i & 1)== 0) i++;
for (int j = i + 1; j < n; j++) {
if (!(s >> j & 1)) continue ;
// cout << s1 << " " << s << "\n" ;
res = min(res, dfs(s ^ (s & is_line[i][j])) + 1);
}
return res;
}
int main () {
#ifdef LOCAL
freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
// freopen("C:\\Users\\Administrator\\Desktop\\out.txt","w",stdout);
#endif
scanf("%d",&T);
int cas = 1;
while (T--) {
MEM(dp);
printf("Case %d: ",cas++);
// cout << "T==" << T << "\n" ;
scanf("%d",&n);
for (int i = 0; i < n; i++) {
scanf("%d%d",&p[i].x,&p[i].y);
}
init();
printf("%d\n",dfs((1 << n) - 1));
}
return 0;
}