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[ ...
随机推荐
- hibernate 对象状态异常:object references an unsaved transient instance - save the transient instance before flushing
我的问题出在,删除的对象对应的表中有一个外键,关联着另外一个表,可是另外一个表中没有数据,所以报了这个错误. 参考http://www.cnblogs.com/onlywujun/archive/20 ...
- oracle数据库的导出与导入
导出:exp devtest10/dev10@172.16.7.39:1521/WSRZ file=d:\WSRZ.dmp log=d:\WSRZ.log full=y 导入:imp testdb/t ...
- SQL Server中Id自增列的最大Id是多少
什么是自增列 在SQL Server中可以将Id列设为自增.即无需为Id指定值,由SQL Server自动给该列赋值,每新增一列Id的值加一,初始值为1. 需要注意的是即使将原先添加的所有数据都删除, ...
- winform中的chat
百度一下 源代码下载:百度一下
- List集合的去除重复性练习
package com.java.b.listdmeo.www; import java.util.ArrayList;import java.util.Iterator; import com.ja ...
- Java面向对象程序设计--接口和内部类
1.接口的定义: In the Java programming language, an interface is not a class but staff[0] = ...
- JVM学习笔记-运行时数据区
不同于C,C++程序,Java程序的内存管理工作由Java虚拟机(JVM)接管,这减低了java程序员的负担,但如果出现内存泄露与溢出问题如报OutOfMemory,StackOverFlow异常错误 ...
- jcarousellite 实现图片列表滚动
jcarousel Lite与jcarousel 相比去掉了皮肤的约束,可以自定义的设置前后按钮和选项卡按钮,生成的html更加简洁,文件更小(2k) 下载链接:http://www.gmarwaha ...
- Android模拟器常用命令收录
一.Linux命令 1.挂载/systme分区为读写状态 mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system 2.切换为Root用户 ...
- hadoo namenode format 异常 java.net.UnknownHostException: localhost.localdomain: localhost.localdomain
/etc/sysconfig/network换成你在hosts里设置的值 /etc/rc.d/init.d/network restart 重启网络 hostname后就会发现hostname变了,也 ...