题目大意:

    一个二维平面上有N个点,一把刷子,刷一次可以把一条线上的所有点都刷掉。问最少刷多少次,可以把全部的点都刷完
状态压缩DP, 用记忆化搜索来写, 需要有个优化不然会超时。
========================================================================================
 
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef long long LL;
#define Max(a,b) (a>b?a:b)
const int INF = 1e9+;
const int maxn = ;
const int MOD = ;
int Line[maxn][maxn];
int dp[], n;
struct node
{
int x, y;
} P[maxn]; int DFS(int sta)
{
if(dp[sta] != - )
return dp[sta];
dp[sta] = INF;
int cnt = ;
for(int i=; i<n; i++)
if( (sta&(<<i)) ) cnt ++; if(cnt == )
return dp[sta] = ;
else if(cnt <= )
return dp[sta] = ; for(int a=; a<n; a++)
{
if( (sta&(<<a)) )
{
for(int b=a+; b<n; b++)
{
if((sta&(<<a)) == ) continue;
int newSta = (sta|Line[a][b]) - Line[a][b];
dp[sta] = min(dp[sta], DFS(newSta) + );
}
break;///此处是优化
}
}
return dp[sta];
} int main()
{
int T, Lim, cas = ;
scanf("%d", &T);
while(T --)
{
memset(dp, -, sizeof(dp));
memset(Line, , sizeof(Line));
scanf("%d",&n);
for(int i=; i<n; i++)
scanf("%d %d", &P[i].x, &P[i].y); for(int i=; i<n; i++)
{
Line[i][i] = (<<i);
for(int j=i+; j<n; j++)
{
for(int k=; k<n; k++)
{
if( (P[i].y-P[j].y)*(P[i].x-P[k].x) == (P[i].y-P[k].y)*(P[i].x-P[j].x) )
Line[i][j] += (<<k);
}
Line[j][i] = Line[i][j];
} }
dp[] = ;
Lim = (<<n)-;
printf("Case %d: %d\n",cas ++ , DFS(Lim));
}
return ;
}

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

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

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

  2. Lightoj 1018 - Brush (IV)

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

  3. 1018 - Brush (IV)

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

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

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

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

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

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

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

  7. Light OJ 1017 - Brush (III)

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

  8. Light OJ 1114 Easily Readable 字典树

    题目来源:Light OJ 1114 Easily Readable 题意:求一个句子有多少种组成方案 仅仅要满足每一个单词的首尾字符一样 中间顺序能够变化 思路:每一个单词除了首尾 中间的字符排序 ...

  9. Light OJ 1429 Assassin`s Creed (II) BFS+缩点+最小路径覆盖

    题目来源:Light OJ 1429 Assassin`s Creed (II) 题意:最少几个人走全然图 能够反复走 有向图 思路:假设是DAG图而且每一个点不能反复走 那么就是裸的最小路径覆盖 如 ...

随机推荐

  1. Android进阶笔记03:Android应用中实现查看"附近的人"的功能

    1. 要实现" 附近的人" 这功能,然后就研究了下: (1)首先要做的就是要获取到自己当前位置的经纬度(编程获取手机GPS定位模块的信息,进而获取自己当前位置的经纬度) (2)然后 ...

  2. iOS viewController 和 view 的创建消失生命周期总结

    控制器创建的生命周期 1. 如果从stroryBoard 中产生一个controller,那么会先调用initWithCoder:, awakeFromNib, loadView,viewDidLoa ...

  3. java io 流基础

  4. inverse 相关设置

    <set name="students" table = "student" inverse="true"> <!-- 指 ...

  5. SQL:42601

    以前遇到SQL中触发器的问题, 添加一个字段后,发现以前的程序的SQL报错 看了下表定义,有这样的一行代码 CREATE TRIGGER chintai_keiyaku_audit AFTER INS ...

  6. C# XML文件操作类XmlHelper

    类的完整代码: using System;using System.Collections;using System.Xml; namespace Keleyi.Com.XmlDAL{public c ...

  7. pthread_rwlock_t读写锁函数说明

    读写锁 索引: 初始化一个读写锁pthread_rwlock_init 读锁定读写锁      pthread_rwlock_rdlock 非阻塞读锁定 pthread_rwlock_tryrdloc ...

  8. javascript——函数内部属性

    <script type="text/javascript"> //在函数内部有两个特殊的属性:arguments 和 this.arguments是一个类数组对象,包 ...

  9. java浮点数剖析

    定点数表达法的缺点在于其形式过于僵硬,固定的小数点位置决定了固定位数的整数部分和小数部分,不利于同时表达特别大的数或者特别小的数.计算机系统采纳了所谓的浮点数表达方式.这种表达方式利用科学计数法来表达 ...

  10. 基于jQuery选择器的整理集合

    jquery对象访问1.each(callback):以每个匹配的元素作为上下文来执行一个函数,return false;停止循环;return true;跳至下一个循环. 来个实例 : 代码如下: ...