Brush (IV) LightOJ - 1018

Mubashwir returned home from the contest and got angry after seeing his room dusty. Who likes to see a dusty room after a brain storming programming contest? After checking a bit he found an old toothbrush in his room. Since the dusts are scattered everywhere, he is a bit confused what to do. So, he called Shakib. Shkib said that, 'Use the brush recursively and clean all the dust, I am cleaning my dust in this way!'

So, Mubashwir got a bit confused, because it's just a tooth brush. So, he will move the brush in a straight line and remove all the dust. Assume that the tooth brush only removes the dusts which lie on the line. But since he has a tooth brush so, he can move the brush in any direction. So, he counts a move as driving the tooth brush in a straight line and removing the dusts in the line.

Now he wants to find the maximum number of moves to remove all dusts. You can assume that dusts are defined as 2D points, and if the brush touches a point, it's cleaned. Since he already had a contest, his head is messy. That's why he wants your help.

Input

Input starts with an integer T (≤ 1000), denoting the number of test cases.

Each case starts with a blank line. The next line contains three integers N (1 ≤ N ≤ 16). N means that there are N dust points. Each of the next N lines will contain two integers xi yi denoting the coordinate of a dust unit. You can assume that (-1000 ≤ xi, yi ≤ 1000) and all points are distinct.

Output

For each case print the case number and the minimum number of moves.

Sample Input

2

 

3

0 0

1 1

2 2

 

3

0 0

1 1

2 3

Sample Output

Case 1: 1

Case 2: 2

题解:http://blog.csdn.net/catglory/article/details/47412409

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<iostream>
 4 #include<algorithm>
 5 using namespace std;
 6 using namespace std;
 7 
 8 const int INF=0x3f3f3f3f;
 9 
10 int n;
11 int line[20][20],x[20],y[20],dp[1<<16];
12 
13 void Init(){
14     memset(dp,0x3f,sizeof(dp));
15     memset(line,0,sizeof(line));
16     dp[0]=0;
17     for(int i=0;i<n;i++){
18         for(int j=i+1;j<n;j++){
19             line[i][j]=(1<<i)|(1<<j);
20             int mx=x[j]-x[i],my=y[j]-y[i];
21             for(int k=j+1;k<n;k++){
22                 int dx=x[k]-x[i],dy=y[k]-y[i];
23                 if(dx*my==dy*mx) line[i][j] |=(1<<k);
24             }
25             line[j][i]=line[i][j];
26         } 
27     }
28 }
29 
30 int DFS(int s){
31     if(dp[s]<INF) return dp[s];
32     int num=__builtin_popcount(s);
33     if(num<=2) return dp[s]=1;
34     int i=0;
35     while(!(s&(1<<i))) i++;
36     for(int j=i+1;j<n;j++){
37         if(!(s&(1<<j))) continue;
38         dp[s]=min(dp[s],DFS(s&(~line[i][j]))+1);
39     }
40     return dp[s];
41 }
42 
43 int main()
44 {   int kase;
45     cin>>kase;
46     for(int t=1;t<=kase;t++){
47         cin>>n;
48         for(int i=0;i<n;i++) cin>>x[i]>>y[i];
49         Init();
50         printf("Case %d: %d\n",t,DFS((1<<n)-1));
51     }
52     return 0;
53 }

 

转载于:https://www.cnblogs.com/zgglj-com/p/7341817.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值