题目大意:

给出n个点的坐标,求至少画多少掉直线才能连接所有点。

题目思路:状态压缩

首先经行预处理,求出所有状态下,那些点不在该状态内

以任意两点为端点求出这条直线的状态

枚举所有状态,找出不在当前状态下的两点,以这两点所形成的直线经行更新dp。

其中dp[i]表示在i状态下的最优解。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#define LL long long
#define MAXSIZE 20
#define INF 0X3f3f3f3f
using namespace std; int dp[],line[MAXSIZE][MAXSIZE];
vector<int>G[]; struct node
{
int x,y;
}point[]; int judge(int a,int b,int c)
{
return (point[a].y - point[c].y)*(point[b].x - point[c].x) == (point[b].y - point[c].y)*(point[a].x - point[c].x);
} int main()
{
for(int i=;i<;i++)
{
G[i].clear();
for(int j=;j<;j++)
{
if((i&(<<j)) == )
G[i].push_back(j);
}
} int T,n,cns=;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=;i<n;i++)
scanf("%d%d",&point[i].x,&point[i].y);
memset(line,,sizeof(line));
memset(dp,INF,sizeof(dp));
for(int i=;i<n;i++)
{
line[i][i]=;
for(int j=i+;j<n;j++)
{
for(int q=;q<n;q++)
{
if(judge(i,j,q))
{
line[i][j] |= (<<q);
}
}
}
}
dp[]=;
for(int i=;i<(<<n);i++)
{
int x=G[i][];
int len=G[i].size();
for(int j=;j<len;j++)
{
int y=G[i][j];
dp[i|line[x][y]] = min(dp[i|line[x][y]],dp[i]+);
}
}
printf("Case %d: %d\n",cns++,dp[(<<n)-]);
}
return ;
}

Light oj 1018 - Brush (IV) 状态压缩的更多相关文章

  1. Light OJ 1018 - Brush (IV)

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

  2. light oj 1011 - Marriage Ceremonies (状态压缩+记忆化搜索)

    题目链接 大概题意是有n个男的n个女的(原谅我这么说,我是粗人),给你一个n*n的矩阵,第i行第j列表示第i个女(男)对第j个男(女)的好感度,然后要安排n对相亲,保证都是正常的(无搞基百合之类的), ...

  3. Light OJ 1021 - Painful Bases(状态压缩DP)

    题目大意: 给你一个base 进制的数字,把这个数字的每一位进行全排列,问有多少个数字是可以整除k的. 题目解析: #include<cstdio> #include<cstring ...

  4. 1018 - Brush (IV)

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

  5. Lightoj 1018 - Brush (IV)

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

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

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

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

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

  8. Light OJ 1019 - Brush (V)(图论-dijkstra)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1019 题目大意:Tanvir想从节点1的位置走到节点n的位置, 输出最短距离, ...

  9. Light OJ 1017 - Brush (III)

    题目大意:     在一个二维平面上有N个点,散落在这个平面上.现在要清理这些点.有一个刷子刷子的宽度是w. 刷子上连着一根绳子,刷子可以水平的移动(在X轴方向上).他可以把刷子放在任何一个地方然后开 ...

随机推荐

  1. Elastic 安装篇(1)

    1.Elasticsearch下载安装 https://www.elastic.co/cn/downloads/elasticsearch 解压: 2.安装head https://github.co ...

  2. HTML学习笔记Day7

    一.position定位属性,检索对象的定位方式 1.语法:{position:static(无特殊定位)/absolute(绝对定位)/relative(相对定位)/fixed(固定定位):} 1) ...

  3. nginx location反向代理不对等时的处理

    server{ server_name git.cheyunhua.top; location /test12/ { proxy_pass https://www.baidu.com/;}} loca ...

  4. python类继承的重写和super

    给已经存在的类添加新的行为,继承是非常好的实现方式.但是如果要改变行为呢?比如在Python继承扩展内置类,我们的contact类只允许一个名字和一个邮箱,但是如果要对某些人增加电话号码呢?这里可以通 ...

  5. Java Web之Servlet的三大作用域对象

    Servlet的作用域是干嘛的?答案就是共享数据而存在的,如图: 下面通过代码演示来具体讲解一下三大作用域 我们新建两个类 package main.com.vae.scope; import jav ...

  6. python 进程锁 生产者消费者模型 队列 (进程其他方法,守护进程,数据共享,进程隔离验证)

    #######################总结######### 主要理解 锁      生产者消费者模型 解耦用的   队列 共享资源的时候 是不安全的 所以用到后面的锁 守护进程:p.daem ...

  7. hbase记录-备份脚本参考

    #!/bin/sh ################################## # CreateDate:// : # ModifyDate:// : ################### ...

  8. shiro默认登录

    业务需要,A项目跳转到B项目进行相关操作.而B项目使用的是shiro登录验证,懵逼了半天,好吧我很菜. 当然你也可以在shiro配置文件中放过这些方法,但是为了安全考虑需要遵守这些规则. 因此A跳转到 ...

  9. System.ComponentModel.DataAnnotations.Schema.TableAttribute 同时存在于EntityFramework.dll和System.ComponentModel.DataAnnotations.dll中

    Entity Framework 与 .net4.5 的 System.ComponentModel.DataAnnotations 都有 System.ComponentModel.DataAnno ...

  10. C#中连接MySQL数据

    小结一下MySQL在C#中是如何连接的,并做一些简单的选择(SELECT).插入( INSERT).更新( UPDATE).删除(DELETE ) (一)连接 a) Firstly, you shou ...