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[ ...
随机推荐
- pl/sql编程
body { font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI ...
- mysql修改字符集 转载
查看编码: show variables like 'collation_%'; show variables like 'character_set_%'; 修改: MySQ ...
- JS-运动框架
写这段代码,是因为之前看过某前RD写过,但在测试过程中发现有不完美的地方. 问题在于判断运动停止条件这里,对于之前停止的判断太片面,只能判断一个条件值时的情况,对于多条件时,会发现运动后的各项值并未达 ...
- NSURLSession -- 备忘
NSURLSession NSURLSession是iOS7出的API,在它之前常用的原生网络库是NSURLConnection,但是因为Connection的使用起来不是很方便 所以我们一直倾向于A ...
- 投稿前必备的cover letter
- Cocos2d-x 2.0以上版本安装方法
1,cd 到2dx根目录,MAC平台使用./create-multi-platform-projects.py 然后提示: -bash: ./create-multi-platform-projec ...
- [Quote]Creating basic Excel workbook with Open XML
Creating basic Excel workbook with Open XML [Quote from]http://www.codeproject.com/Articles/371203/C ...
- Warm up 2
hdu4619:http://acm.hdu.edu.cn/showproblem.php?pid=4619 题意:题目大意:给你两种纸牌 ,一种水平放置共有n张 ,一种竖直放置共有m张.水平放置的纸 ...
- Android 使用HttpClient方式提交POST请求
final String username = usernameEditText.getText().toString().trim(); final String password = passwr ...
- 坑爹的Android Ble 问题记录日志
开发Ble(公司项目,防丢器)已经有一段时间,由于是第一次接触Ble而网上资料又不多,且android平台自身的差异性,遇到了很多问题.为了将来方便查阅,在此做下记录.1.中兴手机,蓝牙手动断开后,无 ...