zoukankan      html  css  js  c++  java
  • Brush (IV) LightOJ

    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
    ",t,DFS((1<<n)-1));
    51     }
    52     return 0;
    53 }
  • 相关阅读:
    VS2005 Web安装程序 创建程序菜单组
    文件夹 文件 加入/去除 Everyone全控
    [转]asp.net 部署数据库、开始菜单、桌面快捷方式实例
    身边的贵人
    AppCode下的cs类 取得相关路径
    遭遇“windows已经阻止此软件因为无法验证发行者”
    成功不是忽悠
    关于 软件注册授权 防止被大面积免费扩散 的设想
    [转]获取机器的硬件信息(CPU ID序列号, 主板信息,硬盘序列号,系统信息)
    递交辞呈之后
  • 原文地址:https://www.cnblogs.com/zgglj-com/p/7341817.html
Copyright © 2011-2022 走看看