【题目链接】 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. 适用于iview的表格转Excel插件

    在网上找的一个表格转excel插件,经过修改后使其适用于iview中的table组件 let idTmr; const getExplorer = () => { let explorer = ...

  2. URAL1277 Cops and Thieves(最小割)

    Cops and Thieves Description: The Galaxy Police (Galaxpol) found out that a notorious gang of thieve ...

  3. eclipse console输出有长度限制

    抓取一个网页内容,然后打印到控制台,发现内容首部都没有了. String content = getResponseText("http://xxx.html"); System. ...

  4. c++(类)构造函数、复制构造函数

    复制构造函数是一种特殊的构造函数,它的作用是用一个已经存在的对象去初始化另一个对象.一般情况下不需要自行定义复制构造函数,系统默认提供一个逐个复制成员值的复制构造函数. 何时要使用呢? 1.将新对象初 ...

  5. HDU4889 Scary Path Finding Algorithm

    Fackyyj loves the challenge phase in TwosigmaCrap(TC). One day, he meet a task asking him to find sh ...

  6. HDU 2089 不要62 (数学)

    题目链接 Problem Description 杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer). 杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了 ...

  7. [bzoj4515][Sdoi2016]游戏-树链剖分+李超线段树

    Brief Description Alice 和 Bob 在玩一个游戏. 游戏在一棵有 n 个点的树上进行.最初,每个点上都只有一个数字,那个数字是 123456789123456789. 有时,A ...

  8. HDU2819(二分图匹配,记录过程)

    Swap Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  9. HDU3664 Permutation Counting

    Permutation Counting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  10. IC卡的传输协议(2)-块传输协议T=1续【转】

    转自:http://bbs.ednchina.com/BLOG_ARTICLE_172025.HTM (3)容错操作 先来看一下容错的规则定义. * 复位应答后,第一个数据块是由终端发往IC卡的,而且 ...