传送门


\(N \leq 20\)很适合暴搜……

第二问最大独立集裸题,\(O(2^NN)\)的算法都能过……

考虑第一问,使用搜索寻找可行解

每一次枚举一条弦的两个端点,通过位运算计算与其相交的弦的数量进行剪枝

一些其他的剪枝:

①两个非\(0\)值中间的所有\(0\)的地位是一样的,所以可以将这些\(0\)缩成一个\(0\)

②每一个连通块分别考虑,可以避免大量的重复情况

#include<bits/stdc++.h>
//This code is written by Itst
using namespace std; inline int read(){
int a = 0;
char c = getchar();
bool f = 0;
while(!isdigit(c) && c != EOF){
if(c == '-')
f = 1;
c = getchar();
}
if(c == EOF)
exit(0);
while(isdigit(c)){
a = a * 10 + c - 48;
c = getchar();
}
return f ? -a : a;
} bitset < 23 > Edge[23] , cur , ans;
int arr[41] , ansArr[41] , times[21] , ind[21] , N , M , len , cntInd , cntA;
bool vis[41];
queue < int > q; bool dfs1(int x){
if(x > cntInd)
return 1;
bitset < 23 > tmp;
for(int i = 1 ; i < x ; ++i)
tmp |= 1 << ind[i];
++len;
for(int i = len ; i > 1 ; --i)
arr[i] = arr[i - 1];
for(int i = 1 ; i <= len ; ++i){
arr[i] = ind[x];
++len;
for(int j = len ; j > i + 1 ; --j)
arr[j] = arr[j - 1];
bitset < 23 > p;
p.set();
for(int j = i + 1 ; j <= len ; ++j){
arr[j] = ind[x];
if((p & tmp) == (Edge[ind[x]] & tmp) && dfs1(x + 1))
return 1;
arr[j] = arr[j + 1];
p[arr[j]] = p[arr[j]] ^ 1;
}
--len;
arr[i] = arr[i + 1];
}
--len;
return 0;
} void dfs2(int x){
if(cur.count() + x <= ans.count())
return;
if(!x)
ans = cur;
if((Edge[x] & cur) == cur){
cur.set(x);
dfs2(x - 1);
cur.reset(x);
}
dfs2(x - 1);
} int main(){
#ifndef ONLINE_JUDGE
freopen("in","r",stdin);
freopen("out","w",stdout);
#endif
N = read();
M = read();
for(int i = 1 ; i <= N ; ++i){
Edge[i].set();
ind[i] = i;
}
for(int i = 1 ; i <= M ; ++i){
int a = read() , b = read();
Edge[a][b] = Edge[b][a] = 0;
}
for(int i = 1 ; i <= N ; ++i)
if(!vis[i]){
vis[i] = 1;
q.push(i);
ind[cntInd = 1] = i;
while(!q.empty()){
int t = q.front();
q.pop();
for(int j = 1 ; j <= N ; ++j)
if(!vis[j] && !Edge[t][j]){
vis[j] = 1;
q.push(j);
ind[++cntInd] = j;
}
}
memset(arr , 0 , sizeof(arr));
if(dfs1(1))
for(int j = 1 ; j <= cntInd * 2 ; ++j)
ansArr[++cntA] = arr[j];
}
for(int i = 1 ; i <= N * 2 ; ++i)
cout << ansArr[i] << ' ';
cout << endl;
cur.reset();
dfs2(N);
cout << ans.count();
return 0;
}

BZOJ3149 CTSC2013 复原 搜索的更多相关文章

  1. 3149: [Ctsc2013]复原

    3149: [Ctsc2013]复原 Time Limit: 10 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 95  Solved: 44[ ...

  2. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  3. [LeetCode] Restore IP Addresses 复原IP地址

    Given a string containing only digits, restore it by returning all possible valid IP address combina ...

  4. 程设大作业xjb写——魔方复原

    鸽了那么久总算期中过[爆]去[炸]了...该是时候写写大作业了 [总不能丢给他们不会写的来做吧 一.三阶魔方的几个基本定义 ↑就像这样,可以定义面的称呼:上U下D左L右R前F后B UD之间的叫E,LR ...

  5. hdu 5535 Cake 构造+记忆化搜索

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=5355 题意:给定n与m,其中1<= n <= 1e5,2 <= m <= 10;问 ...

  6. acm位运算应用 搜索

    acm位运算应用 搜索 搜索    此处不讲题目,只讲位运算是怎样在这些题中实现和应用的.由于搜索题往往是基于对状态的操作,位运算往往特别有效,优化之后的效果可以有目共睹.    例1.POJ 132 ...

  7. HDU-1428(记忆化搜索)

    Problem Description LL 最近沉迷于AC不能自拔,每天寝室.机房两点一线.由于长时间坐在电脑边,缺乏运动.他决定充分利用每次从寝室到机房的时间,在校园里散散步.整个HDU 校园呈方 ...

  8. POJ 1321 棋盘问题(DFS板子题,简单搜索练习)

    棋盘问题 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 44012   Accepted: 21375 Descriptio ...

  9. 力扣算法题—093复原IP地址

    给定一个只包含数字的字符串,复原它并返回所有可能的 IP 地址格式. 示例: 输入: "25525511135" 输出: ["255.255.11.135", ...

随机推荐

  1. python自动化开发-6-常用模块-续

    python的常用模块(续) shelve模块:是一个简单的k,v将内存数据通过文件持久化的模块,可以持久化任何pickle可支持的python数据格式. configparser模块:对配置文件进行 ...

  2. mybatis学习系列五--插件及类型处理器

    2 插件编写(80-81) 单个插件编写 2.1实现interceptor接口(ibatis) invocation.proceed()方法执行必须要有,否则不会无法实现拦截作用 2.2 使用@int ...

  3. Centos 如何关闭自动更新

    法一 安装Centos 6.5后,系统yum自动更新状态默认为开启,若禁止系统自动更新需要手动关闭. 1.进入yum目录 [root@localhost ~]$ cd /etc/yum 2.编辑yum ...

  4. NetBeans数据库笔记---三层架构

    1.创建数据库,数据表 用MySQL数据库和Navicat for MySQL工具创建表 2.创建实体类——反应表结构(列——变量) 也就是对应表建立的gets和sets方法,实体类的名字一般都与数据 ...

  5. 6.1Python文件的操作(一)

    目录 目录 前言 (一)基础类型 ==1.只读== ==2.只写== ==3.追加== (二)b二进制组合 ==1.读写二进制文件== (三)+ 附加组合 ==1.读附加== ==2.写附加== == ...

  6. 2018. first week now at home

    外面雪刚停. 现在是2018.1.5 2018 needs to consider next steps了.未雨绸缪啊     下面是2017年last working day   外面黑了,水面上黑 ...

  7. DP E - Cheapest Palindrome

    Keeping track of all the cows can be a tricky task so Farmer John has installed a system to automate ...

  8. zookeeper+kafka集群安装之中的一个

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/cheungmine/article/details/26678877 zookeeper+kafka ...

  9. SA-题目

    SA的题目 差异:https://lydsy.com/JudgeOnline/problem.php?id=3238 题意概述:给定一个长度为 $n$ 的字符串 $S$,令 $T_ i$ 表示它从第 ...

  10. POJ1419 Graph Coloring

    嘟嘟嘟 求无向图的最大独立集. 有这么一回事:最大独立集=补图的最大团. 所谓的最大团,就是一个子图,满足图中任意两点都有边. 然后ssy巨佬告诉了我一个很没有道理强的做法:随机. 每一次random ...