Lightoj 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 |
/* ***********************************************
Author :guanjun
Created Time :2016/6/22 20:44:30
File Name :1018.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 1000010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std; int dp[maxn],n,l[][];
struct node{
int x,y;
}nod[];
bool Gx(node a,node b,node c){
//int tmp=(a.x*b.y-a.y*b.x)+(b.x*c.y-b.y*c.x)+(c.x*a.y-c.y*a.x);
//if(tmp==0)return true;
if((a.x-b.x)*(c.y-b.y)-(a.y-b.y)*(c.x-b.x)==)return true;
return false;
}
int dfs(int s){
if(dp[s]!=INF)return dp[s];
int cnt=;
for(int i=;i<n;i++)if(s&(<<i))cnt++;
if(cnt==)return ;
if(cnt<=)return ;
for(int i=;i<n;i++){
if(s&(<<i)){
for(int j=i+;j<n;j++){
if(s&(<<j))
dp[s]=min(dp[s],dfs(s-(s&l[i][j]))+);
}
break;
}
}
return dp[s];
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
int T;
cin>>T;
for(int t=;t<=T;t++){
cin>>n;
for(int i=;i<n;i++)scanf("%d %d",&nod[i].x,&nod[i].y);
for(int i=;i<n;i++)l[i][i]=;
for(int i=;i<n;i++){
for(int j=i+;j<n;j++){
l[i][j]=(<<i)|(<<j);
for(int k=;k<n;k++){
if(Gx(nod[i],nod[j],nod[k]))
l[i][j]|=(<<k);
l[j][i]=l[i][j];
}
}
}
int top=<<n;
memset(dp,INF,sizeof dp);
dp[]=;
printf("Case %d: %d\n",t,dfs(top-));
}
return ;
}
Lightoj 1018 - Brush (IV)的更多相关文章
- [LightOJ 1018]Brush (IV)[状压DP]
题目链接:http://lightoj.com/volume_showproblem.php? problem=1018 题意分析:平面上有不超过N个点,如今能够随意方向划直线将它们划去,问:最少要划 ...
- 1018 - Brush (IV)
1018 - Brush (IV) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Muba ...
- Light OJ 1018 - Brush (IV)
题目大意: 一个二维平面上有N个点,一把刷子,刷一次可以把一条线上的所有点都刷掉.问最少刷多少次,可以把全部的点都刷完 状态压缩DP, 用记忆化搜索来写, 需要有个优化不然会超时. ===== ...
- Light oj 1018 - Brush (IV) 状态压缩
题目大意: 给出n个点的坐标,求至少画多少掉直线才能连接所有点. 题目思路:状态压缩 首先经行预处理,求出所有状态下,那些点不在该状态内 以任意两点为端点求出这条直线的状态 枚举所有状态,找出不在当前 ...
- Brush (IV) LightOJ - 1018
题意:平面上有一些点,每刷一次可以把同一条直线上的点都刷光,问最少几次把所有点刷光. 方法: 显然是一个状态压缩dp.ans[S]表示把S集合中点刷掉的最少次数.最开始想到的方法是如果S中只有一个或两 ...
- (状压) Brush (IV) (Light OJ 1018)
http://www.lightoj.com/volume_showproblem.php?problem=1018 Mubashwir returned home from the contes ...
- lightoj 1018 dp
题目链接:http://lightoj.com/volume_showproblem.php?problem=1018 #include <cstdio> #include <cst ...
- lightOJ 1017 Brush (III) DP
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1017 搞了一个下午才弄出来,,,,, 还是线性DP做的不够啊 看过数据量就知道 ...
- LightOJ 1017 - Brush (III) 记忆化搜索+细节
http://www.lightoj.com/volume_showproblem.php?problem=1017 题意:给出刷子的宽和最多横扫次数,问被扫除最多的点是多少个. 思路:状态设计DP[ ...
随机推荐
- ELK的简单安装使用
ELK ELK是什么? Elasticsearch LogStash Kibana 1,简单的安装 我采用的是本地window环境: 下载的包如下: 首先安装的是jdk8,安装完成之后,设 ...
- sql无效字符 执行sql语句报错解决方案
以为是sql中参数赋值有问题,但是将sql语句直接copy到PLSQL中执行,却没问题,纠结了好久,原来是 insert语句多了:唉,坑爹 http://www.jb51.net/article/32 ...
- Python 双向队列Deque、单向队列Queue 模块使用详解
Python 双向队列Deque 模块使用详解 创建双向队列Deque序列 双向队列Deque提供了类似list的操作方法: #!/usr/bin/python3 import collections ...
- SSH常见问题集锦
/WEB-INF/web.xml Web应用程序配置文件,描述了 servlet 和其他的应用组件配置及命名规则. /WEB-INF/classes/包含了站点所有用的 class 文件,包括 ser ...
- CodeForces 22、23部分题解
CodeForces 22A 找严格第二小的...注意只有一种情况,可以sort排序然后unique输出. int a[N]; int main() { int n; while(~scanf(&qu ...
- [Docker]容器镜像
1.rootfs的基础知识 Mount namespaces 隔离的是文件系统挂接点,它使每个容器能看到不同的文件系统层次结构,即每当创建一个新容器时,希望容器进程看到的文件系统时一个独立的隔离环境 ...
- rsync 同步文件重复拷贝问题
rsync 是同步文件的利器,一般用于多个机器之间的文件同步与备份,同时也支持在本地的不同目录之间互相同步文件.在这种场景下,rsync 远比 cp 命令更加合适,它只会同步需要更新的文件,默认情况下 ...
- SpringData JPA进阶查询—JPQL/原生SQL查询、分页处理、部分字段映射查询
上一篇介绍了入门基础篇SpringDataJPA访问数据库.本篇介绍SpringDataJPA进一步的定制化查询,使用JPQL或者SQL进行查询.部分字段映射.分页等.本文尽量以简单的建模与代码进行展 ...
- Solr Admin管理界面使用说明
Notice:本说明基于Solr6.4.2. 本文讨论的是如何使用Solr Admin UI. 一级菜单 图1.SolrCloud模式 图2.单机Solr模式 Logging:展示Solr的日志,不用 ...
- OC-scrollview加载多个控制器界面的优化
在开发过程中,经常有一个控制器中多个字控制器界面的管理,如下图: 这种实现方式,很多种,今天主要记录用scrollview实现的方法.并且只加载当前显示界面的数据. 思路: (1)创建3个需要展示的控 ...