1018 - Brush (IV)
Time Limit: 2 second(s) Memory Limit: 32 MB

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

Output for Sample Input

2

3

0 0

1 1

2 2

3

0 0

1 1

2 3

Case 1: 1

Case 2: 2


PROBLEM SETTER: AKM MUBASHWIR ALAM
SPECIAL THANKS: JANE ALAM JAN (DESCRIPTION, SOLUTION, DATASE
题意:给你n个点,然后要你画直线覆盖这些点,问你最少需要几条线可以覆盖所有的点。
思路:状态压缩dp;
两个点决定一条直线,我们先打表将两点确定的直线和在这个直线上的点处理出来,然后 dp[i]表示 在 状态i时最少要 用的 直线 数,dp[de]=min(dp[i]+1,dp[de]);
那么说下状态i表示的是二进制数,那么i中的0为未覆盖的,1为已经覆盖的,那么当i中当且只有一个1时那么 这时直线数应该为1。那么枚举未覆盖 的点用上面的状态转移 方程 就行,最后dp[(1<<n)-1]就为答案。
  1. 1 #include<stdio.h>
  2. 2 #include<algorithm>
  3. 3 #include<string.h>
  4. 4 #include<stdlib.h>
  5. 5 #include<queue>
  6. 6 #include<iostream>
  7. 7 #include<math.h>
  8. 8 using namespace std;
  9. 9 typedef struct pp
  10. 10 {
  11. 11 int x;
  12. 12 int y;
  13. 13 } ss;
  14. 14 ss ans[200];
  15. 15 int line[20][20];
  16. 16 int ck[75550][20];
  17. 17 int dp[70000];
  18. 18 bool xian(pp a,pp b)
  19. 19 {
  20. 20 return (a.x*b.y-a.y*b.x)==0?true:false;
  21. 21 }
  22. 22 int main(void)
  23. 23 {
  24. 24 int i,j,k;
  25. 25 scanf("%d",&k);
  26. 26 int c;
  27. 27 int n,m;
  28. 28 for(i=0; i<(1<<16); i++)
  29. 29 {
  30. 30 int cc=i;
  31. 31 int u=0;
  32. 32 int t=1;
  33. 33 while(u<16)
  34. 34 {
  35. 35 if(cc%2==0)
  36. 36 {
  37. 37 ck[i][t]=u;
  38. 38 t++;
  39. 39 }
  40. 40 cc/=2;
  41. 41 u++;
  42. 42 }
  43. 43 ck[i][0]=t-1;
  44. 44 }
  45. 45 for(c=1; c<=k; c++)
  46. 46 {
  47. 47
  48. 48 memset(line,0,sizeof(line));
  49. 49 fill(dp,dp+65550,100);
  50. 50 scanf("%d",&n);
  51. 51 int xx;
  52. 52 int yy;
  53. 53 xx=0;
  54. 54 yy=0;
  55. 55 for(i=0; i<n; i++)
  56. 56 {
  57. 57 scanf("%d %d",&ans[i].x,&ans[i].y);
  58. 58 if(ans[i].x!=0||ans[i].y!=0)
  59. 59 xx=ans[i].x,yy=ans[i].y;
  60. 60 }
  61. 61 for(i=0; i<n; i++)
  62. 62 {
  63. 63 for(j=i+1; j<n; j++)
  64. 64 {
  65. 65 line[i][j]|=(1<<i);
  66. 66 line[i][j]|=(1<<j);
  67. 67 for(int s=0; s<n; s++)
  68. 68 {
  69. 69 ss nn;
  70. 70 nn.x=ans[i].x-ans[j].x;
  71. 71 nn.y=ans[i].y-ans[j].y;
  72. 72 ss mm;
  73. 73 mm.x=ans[s].x-ans[j].x;
  74. 74 mm.y=ans[s].y-ans[j].y;
  75. 75 bool ask=xian(nn,mm);
  76. 76 if(ask)
  77. 77 line[i][j]|=(1<<s);
  78. 78 }
  79. 79 line[j][i]=line[i][j];
  80. 80 }
  81. 81 }
  82. 82 int ak=(1<<n)-1;
  83. 83 dp[0]=0;
  84. 84 for(i=0; i<=ak; i++)
  85. 85 {
  86. 86 int uu=i;
  87. 87 int cn=0;
  88. 88 cn=ck[i][0];
  89. 89 cn-=(16-n);
  90. 90 if(n-cn==1)
  91. 91 dp[i]=1;
  92. 92 if(cn>=2)
  93. 93 {
  94. 94 int s;
  95. 95 for(j=1; j<=1; j++)
  96. 96 {
  97. 97 for(s=j+1; s<=cn; s++)
  98. 98 {
  99. 99 int v;
  100. 100 int t=line[ck[i][j]][ck[i][s]];
  101. 101 int de=i;
  102. 102 de|=t;
  103. 103 dp[de]=min(dp[de],dp[i]+1);
  104. 104 }
  105. 105 }
  106. 106 }
  107. 107 }
  108. 108 printf("Case %d: ",c);
  109. 109 printf("%d\n",dp[ak]);
  110. 110 }
  111. 111 return 0;
  112. 112 }

1018 - Brush (IV)的更多相关文章

  1. Lightoj 1018 - Brush (IV)

    1018 - Brush (IV)    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Muba ...

  2. [LightOJ 1018]Brush (IV)[状压DP]

    题目链接:http://lightoj.com/volume_showproblem.php? problem=1018 题意分析:平面上有不超过N个点,如今能够随意方向划直线将它们划去,问:最少要划 ...

  3. Light OJ 1018 - Brush (IV)

    题目大意:     一个二维平面上有N个点,一把刷子,刷一次可以把一条线上的所有点都刷掉.问最少刷多少次,可以把全部的点都刷完 状态压缩DP, 用记忆化搜索来写, 需要有个优化不然会超时. ===== ...

  4. Light oj 1018 - Brush (IV) 状态压缩

    题目大意: 给出n个点的坐标,求至少画多少掉直线才能连接所有点. 题目思路:状态压缩 首先经行预处理,求出所有状态下,那些点不在该状态内 以任意两点为端点求出这条直线的状态 枚举所有状态,找出不在当前 ...

  5. (状压) Brush (IV) (Light OJ 1018)

    http://www.lightoj.com/volume_showproblem.php?problem=1018   Mubashwir returned home from the contes ...

  6. Brush (IV) LightOJ - 1018

    题意:平面上有一些点,每刷一次可以把同一条直线上的点都刷光,问最少几次把所有点刷光. 方法: 显然是一个状态压缩dp.ans[S]表示把S集合中点刷掉的最少次数.最开始想到的方法是如果S中只有一个或两 ...

  7. LightOJ1018 Brush (IV)(状压DP)

    题目大概说一个平面有n个灰尘,可以用一把刷子直直刷过去清理直线上的所有灰尘,问最少要刷几下才能清理完所有灰尘. 首先怎么刷其实是可以确定的,或者说直线有哪些是可以确定的,而最多就有C(n,2)条不一样 ...

  8. lightoj刷题日记

    提高自己的实力, 也为了证明, 开始板刷lightoj,每天题量>=1: 题目的类型会在这边说明,具体见分页博客: SUM=54; 1000 Greetings from LightOJ [简单 ...

  9. dp百题大过关(第一场)

    好吧,这名字真是让我想起了某段被某教科书支配的历史.....各种DP题层出不穷,不过终于做完了orz 虽然各种手糊加乱搞,但还是要总结一下. T1 Monkey Banana Problem    这 ...

随机推荐

  1. three.js很好玩

    能用鼠标拉着转. https://files.cnblogs.com/files/blogs/714801/%E7%A9%BA%E9%97%B4%E5%87%A0%E4%BD%95.7z var po ...

  2. tomcat在eclipse上发布,Perference下的server找不到解决办法

    help--->Install New software得到如下所示 下面work with选项的内容与你的eclipse版本有关 我的eclipse版本为eclipse-java-2019-0 ...

  3. Kafka 集群安装部署

    2.1 安装部署 2.1.1 集群规划 192.168.1.102 192.168.1.103 192.168.1.104 zookeeper zookeeper zookeeper kafka ka ...

  4. Gitlab安装操作说明书

    一.Gitlab安装操作步骤 登录官方网站https://about.gitlab.com/downloads/根据你所需要的系统版本,作者使用的是centos6, 检查您的服务器是否符合硬件要求.g ...

  5. Spring事务隔离级别和传播特性(转)

    相信每个人都被问过无数次Spring声明式事务的隔离级别和传播机制吧!今天我也来说说这两个东西. 加入一个小插曲,一天电话里有人问我声明式事务隔离级别有哪几种,我就回答了7种,他问我Spring的版本 ...

  6. 「Python实用秘技02」给Python函数定“闹钟”

    本文完整示例代码及文件已上传至我的Github仓库https://github.com/CNFeffery/PythonPracticalSkills 这是我的系列文章「Python实用秘技」的第2期 ...

  7. Jenkins视图管理

    目录 一.简介 二.视图维护 创建视图 将项目加入视图中 三.状态图标变绿 四.看板 一.简介 在现在的编程中,公司往往采用的是模块化的编程方式,也就是说将一个项目拆分成许多模块,每个小项目组往往只负 ...

  8. Sentry 开发者贡献指南 - 后端服务(Python/Go/Rust/NodeJS)

    内容整理自官方开发文档 系列 1 分钟快速使用 Docker 上手最新版 Sentry-CLI - 创建版本 快速使用 Docker 上手 Sentry-CLI - 30 秒上手 Source Map ...

  9. 资源日历关联(Project)

    <Project2016 企业项目管理实践>张会斌 董方好 编著 其实,[日历]并不是[任务]的唯一,他还有另一个老相好:[资源]. 是啊,就像张同学给的例子那样,得为一个专门的外聘专家这 ...

  10. CF916A Jamie and Alarm Snooze 题解

    Content 令一个时间为幸运时间,当且仅当该时间中包含数字 \(7\). 小 J 很懒,他决定在 \(h\) 时 \(m\) 分起床,于是他将闹钟设定在一个很幸运的时间,并通过按一次按钮以多睡 \ ...