zoukankan      html  css  js  c++  java
  • BZOJ5299 [Cqoi2018]解锁屏幕 【状压dp】

    题目链接

    BZOJ5299

    题解

    就一个毒瘤卡常题。。写了那么久
    (f[i][s])表示选了集合(s)中的点,最后一个是(i),进行转移
    要先预处理出两点间的点,然后卡卡常就可以过了

    #include<algorithm>
    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<cmath>
    #include<queue>
    #include<map>
    #define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
    #define REP(i,n) for (register int i = 1; i <= (n); i++)
    #define mp(a,b) make_pair<int,int>(a,b)
    #define cls(s) memset(s,0,sizeof(s))
    #define cp pair<int,int>
    #define LL long long int
    #define lbt(x) (x & -x)
    #define res register
    using namespace std;
    const int maxn = 23,maxm = (1 << 21),INF = 1000000000,P = 100000007;
    inline int read(){
    	int out = 0,flag = 1; char c = getchar();
    	while (c < 48 || c > 57){if (c == '-') flag = -1; c = getchar();}
    	while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();}
    	return out * flag;
    }
    int X[maxn],Y[maxn];
    inline void add(int& x,int y){
    	x += y;
    	if (x >= P) x -= P;
    }
    int n,bin[maxn],f[maxn][maxm],vis[maxn][maxm],a[maxn][maxn];
    inline bool onit(int k,int i,int j){
    	if (X[k] < min(X[i],X[j]) || X[k] > max(X[i],X[j]) || Y[k] < min(Y[i],Y[j]) || Y[k] > max(Y[i],Y[j]))
    		return false;
    	return (X[j] - X[i]) * (Y[k] - Y[i]) - (Y[j] - Y[i]) * (X[k] - X[i]) == 0;
    }
    inline bool is4(int s){
    	int cnt = 0;
    	while (s) cnt++,s -= lbt(s);
    	return cnt >= 4;
    }
    inline void init(){
    	for (res int i = 0; i < n; i++)
    		for (res int j = 0; j < n; j++)
    			if (j != i)
    				for (res int k = 0; k < n; k++)
    					if (k != i && k != j && onit(k,i,j))
    						a[i][j] |= bin[k];
    }
    inline void solve(){
    	int ans = 0,maxv = (1 << n) - 1;
    	for (int i = 0; i < n; i++) f[i][bin[i]] = 1;
    	for (res int s = 0; s <= maxv; s++)
    		for (res int u = 0; u < n; u++)
    			if (f[u][s]){
    				for (int j = 0; j < n; j++) if (!(s & bin[j])){
    					if ((s & a[u][j]) != a[u][j]) continue;
    					add(f[j][s | bin[j]],f[u][s]);
    				}
    			}
    	for (res int s = 0; s <= maxv; s++) if (is4(s))
    		for (int i = 0; i < n; i++) add(ans,f[i][s]);
    	printf("%d
    ",ans);
    }
    int main(){
    	bin[0] = 1; for (res int i = 1; i < maxn; i++) bin[i] = bin[i - 1] << 1;
    	n = read();
    	for (res int i = 0; i < n; i++) X[i] = read(),Y[i] = read();
    	init();
    	solve();
    	return 0;
    }
    
    
  • 相关阅读:
    Datastage 调度相关 dsjob
    DropdownList内容树状展示 字段前空格不显示
    IE兼容低版本设置
    跑数速度慢,修改参数
    cognos samples 安装配置【转】
    在子窗口中操作父窗口(刷新)
    html长文本自动换行
    Asp.net禁止缓存
    【Range Lookup】 根据年龄 求年龄分段ID
    目标表已有对应数据则不插入
  • 原文地址:https://www.cnblogs.com/Mychael/p/9041251.html
Copyright © 2011-2022 走看看