lightoj 1018 dp
题目链接:http://lightoj.com/volume_showproblem.php?problem=1018
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std; const int maxe = ;
const int maxn = ;
const int INF = 0x3f3f3f;
int X[maxn],Y[maxn];
int S[maxn][maxn];
int T,N;
int dp[<<maxn];
int a[<<maxn]; int Cross(int x1,int y1,int x2,int y2){
return x1*y2 - y1 * x2;
}
void init(){
for(int i=;i<maxn;i++) a[<<i]=i;
}
int dfs(int x){ //求点集S。
if(dp[x]!=-) return dp[x];
int i=a[x&-x]; //点集S的最低位上的点。
dp[x]=INF;
for(int k=x-(x&-x);k;k-=k&-k){ //S-(S&-S)是去除i后的点集。
int j=a[k&(-k)];
dp[x]=min(dp[x],dfs(x^(S[i][j]&x))+);
}
return dp[x];
}
int main()
{
//freopen("E:\\acm\\input.txt","r",stdin); init();
cin>>T;
for(int cas=;cas<=T;cas++){
scanf("%d",&N);
for(int i=;i<N;i++) scanf("%d %d",&X[i],&Y[i]); memset(S,,sizeof(S));
for(int i=;i<N;i++)
for(int j=i+;j<N;j++){
for(int k=;k<N;k++){
if(!Cross(X[j]-X[i],Y[j]-Y[i],X[k]-X[i],Y[k]-Y[i]))
S[i][j] |= (<<k); //i,j所在直线上其他点的集合。
}
S[j][i] = S[i][j];
}
int ALL = (<<N)-;
memset(dp,-,sizeof(dp));
dp[] = ;
for(int i=;i<N;i++) dp[<<i] = ;
printf("Case %d: %d\n",cas,dfs(ALL));
}
}
lightoj 1018 dp的更多相关文章
- [LightOJ 1018]Brush (IV)[状压DP]
题目链接:http://lightoj.com/volume_showproblem.php? problem=1018 题意分析:平面上有不超过N个点,如今能够随意方向划直线将它们划去,问:最少要划 ...
- lightoj 1018 (状态压缩DP)
设dp[s]表示状态s下所需要的线段的个数,s的二进制中第x位为1就表示该状态下第x个点没被线段覆盖.需要预处理出来在任意两点之间连线所覆盖点的状态O(n^3),然后记忆化搜索即可. #include ...
- lightoj 1036 dp
题目链接:http://lightoj.com/volume_showproblem.php?problem=1036 #include <cstdio> #include <cst ...
- lightoj 1004 dp:数字三角形
题目链接:http://lightoj.com/volume_showproblem.php?problem=1004 #include <cstdio> #include <cst ...
- Lightoj 1018 - Brush (IV)
1018 - Brush (IV) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Muba ...
- lightoj 1013 dp
题目链接:http://lightoj.com/volume_showproblem.php?problem=1013 #include <cstdio> #include <cst ...
- poj 1018(dp)
Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25653 Accepted: ...
- Brush (IV) LightOJ - 1018
题意:平面上有一些点,每刷一次可以把同一条直线上的点都刷光,问最少几次把所有点刷光. 方法: 显然是一个状态压缩dp.ans[S]表示把S集合中点刷掉的最少次数.最开始想到的方法是如果S中只有一个或两 ...
- LightOJ 1017 - Brush (III) 记忆化搜索+细节
http://www.lightoj.com/volume_showproblem.php?problem=1017 题意:给出刷子的宽和最多横扫次数,问被扫除最多的点是多少个. 思路:状态设计DP[ ...
随机推荐
- struts通过Ajax返回数据时,例如对象类型,没有执行Ajax的回调函数
<result type="json" name="success"> <param name=" ...
- python基础(目录)
1.数据库操作入门 2.网络编程入门 3.编码规范 4.测试
- angularJS广播
控制器之间共享数据(向父级/子级控制器传递event,data),类似于service在不同的控制器中通信 html: <div ng-controller="ParentCtrl&q ...
- 解决Oracle clob字段数据过大问题
select * from user_lobs where table_name='WX_MAIL';--SYS_LOB0001313121C00015$$ MB FROM user_segments ...
- ubuntu1404安装配置java环境(jdk8)
这个安装比较简单,网上也有数不清的教学,我这里记录以下,方便以后万一失忆了回来看看能想起来.个人博客http://www.cnblogs.com/wdfwolf3/ 1.下载安装 言归正传,我们需要到 ...
- sec:authorize 标签 通过不通过权限例子
1. 方式一 <sec:authorize ifAnyGranted="ROLE_A"> <a href="a.jsp"> ...
- java 使用substring 截取特殊字符串的后一位或者数字
关于截取特殊的字符串的后一位或者数字 需求:截取特殊字符为 . 后一位 String[] str = uri.split("/"); String str1 = str[st ...
- PYTHON开发--面向对象基础二
一.成员修饰符 共有成员 私有成员, __字段名 - 无法直接访问,只能间接访问 1. 私有成员 1.1 普通方法种的私有成员 class Foo: def __init__(self, n ...
- python入门笔记第一天
查询acsii命令 ord(‘A’) 导入模块python执行系统命令显示文件.查找文件方法1import osa = os.popen('目标').read()a 解释output = os.pop ...
- AngularJS测试框架 karma备忘
AngularJS测试框架karma安装 安装karma $ --save-dev 安装karma组件 $ npm install karma-jasmine karma-chrome-launche ...