题目大意:

给出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. macs 学习

    点击 首先andriomianfest主配文件(主要配置文件),来启动主要的activity对象,然后通过该对象调用create方法来加载布局文件xml active通过布局文件的控件生成相应的对象. ...

  2. java List集合

    List集合包括四种类,分别是ArrayList.LinkedList.Vector.Stack. ArrayList:元素的存储是顺序存储,可以根据数组的下标查询,查询速度快,但是在删除和插入元素时 ...

  3. maomao的fft板子

    \(QwQ\) #include <cmath> #include <cstdio> #include <cstring> #include <iostrea ...

  4. CodeForces1073E 数位dp+状压dp

    http://codeforces.com/problemset/problem/1073/E 题意 给定K,L,R,求L~R之间最多不包含超过K个数码的数的和. 显然这是一道数位dp,在做的过程中会 ...

  5. 2017-12-15python全栈9期第二天第四节之格式化输出%s和个人简介模板

    #!/user/bin/python# -*- coding:utf-8 -*-msg = '''-----------info of zd----------------Name:zdage:24h ...

  6. Centos 7最小化Mongodb部署操作

    基本组件 mongodb-org mongodb-org-server mongodb-org-mongos mongodb-org-shell mongodb-org-tools 文件位置 /var ...

  7. Windows下的包管理工具-Scoop

    关于scoop的介绍 https://www.jianshu.com/p/bb0ba62b519c https://blog.csdn.net/fcymk2/article/details/86653 ...

  8. Junit4学习与使用【转】

    参考: http://blog.csdn.net/qqhjqs/article/details/42219037

  9. 043、data-packed volume container (2019-03-06 周三)

    参考https://www.cnblogs.com/CloudMan6/p/7203285.html     volume container 的数据归根到底还是在host上,我们能不能把数据完全放到 ...

  10. ueditor 百度编辑器 粘贴的table表格样式边线

    粘贴html的table表格会有间隔大,黑色边线,可以在: ueditor.all.js 里 找到以下处,修改里面的样式即可 me.ready(function () { utils.cssRule( ...