题目大意:

    一个二维平面上有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(java)学习笔记202:Handler消息机制的原理和实现

     联合学习 Android 异步消息处理机制 让你深入理解 Looper.Handler.Message三者关系   1. 首先我们通过一个实例案例来引出一个异常: (1)布局文件activity_m ...

  2. css考核点整理(六)-水平居中定位的几种方式

     定宽    text-align: center 父容器position:relative:子容器 position:absolute;left:50%; margin-left: 宽度/2 .Ce ...

  3. Linux下长时间ping网络加时间戳并记录到文本(转)

    [root@test ~]# ping 192.168.2.1 -c 10 PING 192.168.2.1 (192.168.2.1) 56(84) bytes of data.64 bytes f ...

  4. PHP 解决未定义变量报错

    在PHP中 有时候会出现 Notice: Undefined index: sid in D:\Apache Group\Apache2\htdocs\php_mobile\mobile\chao\s ...

  5. Andoird - SQLite 数据库 基础教程

    链接来源 http://www.tutorialspoint.com/android/android_sqlite_database.htm SQLite是一个开源的SQL数据库,这个数据库把数据存储 ...

  6. 分享整理的sql脚本

    1. 表空间使用率 SQL> select  a.tablespace_name,  2          round(a.total_size) "total_size M" ...

  7. Core Animation系列之CADisplayLink(转)

    转自 http://www.tuicool.com/articles/meMVR3 一直以来都想好好学习下CoreAnimation,奈何涉及的东西太多,想要一次性全部搞定时间上不允许,以后会断断续续 ...

  8. VS 编程常见错误及解决方法

    1. VS2013 无法打开包括文件:“cv.h"等一些头文件 解决方法: cv.h是build\include文件夹下的头文件,所在文件夹位置是D:\Program Files (x86) ...

  9. 安装freebsd9 出现 mountroot>怎么办

    之前手欠把linux分区给删了想重装freebsd 重新进入的时候mbr提示grub信息 用PE把MBR删掉 之后再用freebsd光盘启动出现mountroot> 就用mountroot> ...

  10. Java学习----到底调用哪一个方法(多态)

    public class Father { public void print() { System.out.println("Father:print()"); } } publ ...