bzoj5299: [Cqoi2018]解锁屏幕
题目链接
题解
很水的装压dp,相信没人需要看题解....
dp[i][j]表示状态为i最后一个到的点为j,然后转移就很好写了
不过 我读入优化没读负数 ,为什么mod1e8 +7,我 mod 1e9 + 7 啊,WA了两发
#include<cstdio>
#include<vector>
#include<algorithm>
inline int read() {
int x = 0,f = 1;
char c = getchar();
while(c < '0' || c > '9'){if(c == '-')f = -1; c = getchar();}
while(c <= '9' && c >= '0')x = x * 10 + c - '0',c = getchar();
return x * f;
}
#define mod 100000007
int n;
const int maxn = 21;
struct node {
int x,y;
bool operator < (const node &a)const {
if(x == a.x) return y < a.y;
return x < a.x;
}
} loc[maxn];
int dp[(1 << maxn) + 7][maxn];
int po[maxn][maxn];
void get(node x,node y,int X,int Y) {
int a = y.y - x.y , b = x.x - y.x , c = y.x * x.y - x.x * y.y;
int tmp = 0;
for(int i = X + 1;i < Y;++ i) {
if(loc[i].x * a + loc[i].y * b + c == 0)
tmp |= (1 << i);
//if(i != Y)vec[X].push_back(i); if(i != X)vec[Y].pish_back(i);
}
po[X][Y] = tmp | (1 << X); // ^ (1 << Y);
po[Y][X] = tmp | (1 << Y); // ^ (1 << X);
//printf("%d\n",tmp);
}
int main() {
n = read();
for(int i = 0;i < n;++ i)
loc[i].x = read(),loc[i].y = read();
std::sort(loc,loc + n);
for(int i = 0;i < n;++ i)
for(int j = i + 1;j < n;++ j)
get(loc[i],loc[j],i,j);
int ans = 0;
for(int i = 0;i < n;++ i) dp[1 << i][i] = 1;
for(int i = 0;i < (1 << n);++ i) {
//ans = 0;
for(int j = 0;j < n;++ j) {
if(((1 << j) & i)) continue;
for(int k = 0;k < n;++ k) {
if(!((1 << k) & i)) continue;
if((po[k][j] & i) == po[k][j]){dp[i | (1 << j)][j] = (dp[i | (1 << j)][j] + dp[i][k]) % mod;}
}
}
}
for(int K,i = 0;i < (1 << n);++ i) {
K = 0;
for(int t = i;t;t >>= 1) if(t & 1)K ++;
if(K >= 4) {
for(int k = 0;k < n;++ k)
ans = (ans + dp[i][k]) % mod;
}
}
printf("%d\n",ans);
return 0;
}
bzoj5299: [Cqoi2018]解锁屏幕的更多相关文章
- BZOJ5299:[CQOI2018]解锁屏幕(状压DP)
Description 使用过Android手机的同学一定对手势解锁屏幕不陌生.Android的解锁屏幕由3x3个点组成,手指在屏幕上画一条 线将其中一些点连接起来,即可构成一个解锁图案.如下面三个例 ...
- BZOJ5299 [Cqoi2018]解锁屏幕 【状压dp】
题目链接 BZOJ5299 题解 就一个毒瘤卡常题..写了那么久 设\(f[i][s]\)表示选了集合\(s\)中的点,最后一个是\(i\),进行转移 要先预处理出两点间的点,然后卡卡常就可以过了 # ...
- [Luogu] P4460 [CQOI2018]解锁屏幕
题目背景 使用过Android 手机的同学一定对手势解锁屏幕不陌生.Android 的解锁屏幕由3X3 个点组成,手指在屏幕上画一条线,将其中一些点连接起来,即可构成一个解锁图案.如下面三个例子所示: ...
- P4460 [CQOI2018]解锁屏幕
算是我比较擅长的类型,自己想想就会了.普通小状压,状态傻子都能想出来.一开始裸的枚举T了,30.后来与处理之后跑的飞起,就是不对,还是30分.后来看讨论版...mod竟然是1e8+7!!!这不有毒吗. ...
- [CQOI2018]解锁屏幕
嘟嘟嘟 这题感觉真的很简单-- \(O(n ^ 2 logn)\)的做法特别好理解,但得开O2. 看数据范围,肯定是状压dp.但刚开始我没想通状压啥,因为点与点之间还有顺序问题.但后来发现这个顺序是子 ...
- 【[CQOI2018]解锁屏幕】
状压这个东西好像没有什么能优化的高级东西,像什么斜率优化,单调队列在状压的优化上都很少见 而最常见的状压优化就是预处理优化了, 这道题就预处理一下所有点对之间连线上的点,之后压成状态就能做到\(O(2 ...
- BZOJ 5299: [Cqoi2018]解锁屏幕
状压DP #include<cstdio> using namespace std; const int mod=1e8+7; int F[1000005][25],dis[25][25] ...
- bzoj 5299: [Cqoi2018]解锁屏幕 状压dp+二进制
比较简单的状压 dp,令 $f[S][i]$ 表示已经经过的点集为 $S$,且最后一个访问的位置为 $i$ 的方案数. 然后随便转移一下就可以了,可以用 $lowbit$ 来优化一下枚举. code: ...
- 【BZOJ5299】【CQOI2018】解锁屏幕(动态规划,状态压缩)
[BZOJ5299][CQOI2018]解锁屏幕(动态规划,状态压缩) 题面 BZOJ 洛谷 Description 使用过Android手机的同学一定对手势解锁屏幕不陌生.Android的解锁屏幕由 ...
随机推荐
- Spring boot初始
1 创建pom.xml parent:org.springframework.boot 包含启动的依赖 添加依赖,如 spring-boot-starter-web mvn dependency:t ...
- $this->success()传值不完整
public function manager_doExport() { $search=$_POST['search']; //前台输入2017-12-1,即,$search['starttime' ...
- 商城项目(ssm+dubbo+nginx+mysql统合项目)总结(1)
我不会在这里贴代码和详细步骤什么的,我觉得就算我把它贴出来,你们照着步骤做还是会出很多问题,我推荐你们去看一下黑马的这个视频,我个人感觉很不错,一步一步走下来可以学到很多东西.另外,视频和相关文档的话 ...
- Django 1.10中文文档-第一个应用Part7-自定义管理站点
开发第一个Django应用,Part7 本教程上接Part6.将继续完成这个投票应用,本节将着重讲解如果用Django自动生成后台管理网站. 自定义管理表单 通过admin.site.register ...
- LCD驱动分析【转】
转自:http://blog.csdn.net/hanmengaidudu/article/details/21559153 1.S3C2440上LCD驱动 (FrameBuffer)实例开发讲解 其 ...
- WebClient vs HttpClient vs HttpWebRequest
转载:http://www.diogonunes.com/blog/webclient-vs-httpclient-vs-httpwebrequest/ Just when I was startin ...
- 2017 NWERC
2017 NWERC Problem A. Ascending Photo 题目描述:给出一个序列,将其分成\(m\)份(不需要均等),使得将这\(m\)份重新排列后构成的是不下降序列,输出最小的\( ...
- Ubuntu vi 上下左右变ABCD问题解决方法
---恢复内容开始--- 错误问题:vi上下左右键显示为ABCD的问题 解决方法: 只要依次执行以下两个命令即可完美解决Ubuntu下vi编辑器方向键变字母的问题. 一.执行命令 sudo apt-g ...
- angular项目中使用ngSemantic
npm install ng-semantic --save npm install jquery --save 下载 Official Semantic UI bundle ( .zip ) fro ...
- SLD 官方实例
基于xml标准的sld格式: <?xml version="1.0" encoding="UTF-8"?> <StyledLayerDescr ...