【题目链接】 LInk

【题目大意】

  给出一些点和边,选择一个点就能把这个点和相邻的点都覆盖,求最小点覆盖

【题解】

  我们压缩点被覆盖的状态,迭代加深搜索覆盖的最小点数,
  当剩余的点全部选上时都无法完全覆盖就剪枝。

【代码】

#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N=36;
int i,n,m,x,y,limit;
LL st[N],Lft[N],Final;
bool dfs(int pos,int d,LL St){
//printf("%d %d %lld\n",d,pos,st);
if(St==Final)return 1;
if(pos>n||d==limit)return 0;
for(int i=pos;i<=n;i++){
if((St|Lft[i])!=Final)break;
if(st[i]&St==st[i])continue;
if(dfs(i+1,d+1,St|st[i]))return 1;
}return 0;
}
void solve(){
Final=(1LL<<n)-1;
for(int i=1;i<=n;i++)st[i]=1LL<<(i-1);
for(int i=1;i<=m;i++){
scanf("%d%d",&x,&y);
st[x]|=1LL<<(y-1);
st[y]|=1LL<<(x-1);
}for(Lft[n]=st[n],i=n-1;i;i--)Lft[i]=(st[i]|Lft[i+1]);
for(limit=1;limit<=n;limit++)if(dfs(1,0,0)){printf("%d\n",limit);break;}
}
int main(){
while(scanf("%d%d",&n,&m),n+m)solve();
return 0;
}

  

UVA 10160 Servicing Stations(状态压缩+迭代加深)的更多相关文章

  1. uva 10160 Servicing Stations(DFS+剪枝)

    Servicing stations A company offers personal computers for sale in N towns (3 <= N <= 35). The ...

  2. UVA 10160 Servicing Stations(深搜 + 剪枝)

    Problem D: Servicing stations A company offers personal computers for sale in N towns (3 <= N < ...

  3. UVA - 11214 Guarding the Chessboard(迭代加深搜索)

    题目: 输入一个n*m的棋盘(n,m<10),某些格子有标记,用最少的皇后守卫(即占据或攻击)所有的标记的格子.输出皇后的个数. 思路: 一开始没有想到用迭代加深搜索,直接dfs结果还没写完就发 ...

  4. UVA 1508 - Equipment dp状态压缩

    题意:  已知n个5元组,从中选出k组,使得这些组中5个位置,每个位置上最大数之和最大. 分析:当k>5时,就是n个5元组最大的数之和,当k<5时,就当做5元组,状态压缩,用00000表示 ...

  5. UVA 11464 - Even Parity 状态压缩,分析 难度: 2

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  6. UVA 10651 Pebble Solitaire 状态压缩dp

    一开始还在纠结怎么表示一个状态,毕竟是一个串.后来搜了一下题解发现了这里用一个整数的前12位表示转态就好了 ,1~o,0~'-',每个状态用一个数来表示,然后dp写起来就比较方便了. 代码: #inc ...

  7. UVA 11825 - Hackers&#39; Crackdown 状态压缩 dp 枚举子集

    UVA 11825 - Hackers' Crackdown 状态压缩 dp 枚举子集 ACM 题目地址:option=com_onlinejudge&Itemid=8&page=sh ...

  8. uva 11195 Another queen (用状态压缩解决N后问题)

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  9. UVA 1508 - Equipment 状态压缩 枚举子集 dfs

    UVA 1508 - Equipment 状态压缩 枚举子集 dfs ACM 题目地址:option=com_onlinejudge&Itemid=8&category=457& ...

随机推荐

  1. json 串转成 java 对象再拼接成前台 html 元素

    获取商品参数 json 串,转成 java 对象,再拼接成前台 html 的Service方法 @Override public String getItemParam(Long itemId) { ...

  2. Ubuntu下使用mysqli-connect连接mysql时报错:ERROR 1698 (28000): Access denied for user 'root'@'localhost'

    LNMP安装好后,写了个index.php文件,里面的内容很简单,就是想测试php与mysql的通信是否正常,代码如下: <?php $host = 'localhost'; $user = ' ...

  3. BZOJ1191:超级英雄(二分图匹配)

    [HNOI2006]超级英雄Hero 题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1191 Description: 现在电视台有一种节 ...

  4. codeforces 1015A

    A. Points in Segments time limit per test 1 second memory limit per test 256 megabytes input standar ...

  5. centos安装net-speeder

    以前介绍过VPS上安装锐速对VPS的加速效果,但是这货对 Linux 内核有要求,一般就只能在XEN或者KVM的机子上安装.不过还好锐速有一个免费的代替品:net-speeder,所以这里介绍一下 D ...

  6. Python-Jenkins API使用

    一.概述 最近在工作中需要用到在后台代码中触发Jenkins任务的构建,于是想到Jenkins是否有一些已经封装好的API类库提供,用于处理跟Jenkins相关的操作.下面就简单介绍下我的发现. 二. ...

  7. DOM操作的一个小坑

    最近在苦读<JavaScript高级程序教程>,真不愧是前端圣经,学到了很多东西. nodeList.NameNodeMap.HTMLCollection这三个集合是动态的!每当文档发生变 ...

  8. idea真不习惯啊

    http://blog.csdn.net/z69183787/article/details/41416189

  9. noip2014 提高组

    T1 生活大爆炸版 石头剪刀布 题目传送门 就是道模拟题咯 #include<algorithm> #include<cstdio> #include<cstring&g ...

  10. [Codevs1519]过路费解题报告|最小生成树|LCA

    在某个遥远的国家里,有 n个城市.编号为 1,2,3,…,n.这个国家的政府修建了m 条双向道路,每条道路连接着两个城市.政府规定从城市 S 到城市T需要收取的过路费为所经过城市之间道路长度的最大值. ...