【题目链接】 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. Virtualization solutions on Linux systems - KVM and VirtualBox

    Introduction Virtualization packages are means for users to run various operating systems without &q ...

  2. css之postion定位

    css position之初识 我们先看看position定位有那几个属性,下面是我从w3c的截图,为我们认识定位做初步的了解 通过上面这张图嘞,我们知道了position有5个属性,那么下面,我就来 ...

  3. xcode 10 出现 :-1: Multiple commands produce '/Users/.../Library/Developer/Xcode/DerivedData/.../Build/Products/Dev-iphonesimulator/TLYShyNavBar/TLYShyNavBar.framework/Info.plist': 1) Target 'TLYShyNavB

    错误提示如下: :-1: Multiple commands produce '/Users/.../Library/Developer/Xcode/DerivedData/.../Build/Pro ...

  4. BZOJ 2063: 我爸是李刚

    2063: 我爸是李刚 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 155  Solved: 82[Submit][Status][Discuss] ...

  5. bzoj 1005 组合数学 Purfer Sequence

    这题需要了解一种数列: Purfer Sequence 我们知道,一棵树可以用括号序列来表示,但是,一棵顶点标号(1~n)的树,还可以用一个叫做 Purfer Sequence 的数列表示 一个含有 ...

  6. cobalt strike使用笔记

    启动: ./teamserver 192.168.74.1 admin #启动cs服务器.admin为密码. 监听器: windows/beacon_dns/reverse_dns_txtwindow ...

  7. shell脚本之while for if 语句和编写计划任务

    关于while循环: while do done 例如 1.关于内存的实时操作: (1).vim a.sh (2).输入以下while循环 (3)../a.sh执行脚本 2.自加一的操作: (1).v ...

  8. 操作MySQL数据库相关代码

    注意事项: 1.导入驱动包,如我导的是mysql-connector-java-5.1.26-bin.jar 2.修改下面代码中的用户名和密码 3.其中URL为"jdbc:mysql://数 ...

  9. 【 Keepalived 】Nginx or Http 主-备模式

    一.主-备模式: 操作系统:centos 6.4 x64 ka1: 192.168.2.10 ka2: 192.168.2.11 vip: 192.168.2.200 ka1-master服务器配置 ...

  10. heightCharts改变图表内图标的样式:链接外部图片

    series: [{ name: '东京', marker: { symbol: 'url(https://www.highcharts.com/demo/gfx/sun.png)'     //链接 ...