【题目链接】 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. Codeforces 931.D Peculiar apple-tree

    D. Peculiar apple-tree time limit per test 1 second memory limit per test 256 megabytes input standa ...

  2. Git远程仓库的使用(github为例)

    一.           创建SSH key 输入命令“ssh-keygen –t rsa”创建ssh key.   由于笔者pc机已有ssh key,这里不再重复创建覆盖,仅做演示. 笔者创建好的s ...

  3. nginx反向代理Tomcat/Jetty获取客户端IP地址

    使用nginx做反向代理,Tomcat服务器和Jetty服务器如何获取客户端真实IP地址呢?首先nginx需要配置proxy_set_header,这样JSP使用request.getHeader(& ...

  4. Node.js 编码转换

    Node.js自带的toString()方法不支持gbk,因此中文转换的时候需要加载第三方库,推荐以下两个编码转换库,iconv-lite和encoding.       iconv, iconv-l ...

  5. bzoj 1996 DP

    我们可以发现,对于最后队列的一段区间[i,j],不论这一段区间如何插入,除了最后一个插入的对象外,剩下的对后续插入没有影响,这启发我们可以用DP来解决这一问题. w[i][j][0..1]代表区间[i ...

  6. Educational Codeforces Round 40 A B C D E G

    A. Diagonal Walking 题意 将一个序列中所有的\('RU'\)或者\('UR'\)替换成\('D'\),问最终得到的序列最短长度为多少. 思路 贪心 Code #include &l ...

  7. 如何加快Eclipse的启动速度?

    http://it.taocms.org/12/6457.htm 浅析配置更快的Eclipse方法 What is the Metadata GC Threshold and how do I tun ...

  8. SpringMvc基础知识(二) springmvc和mybatis整合

    1 springmvc和mybatis整合 1.1 需求 使用springmvc和mybatis完成商品列表查询. 1.2 整合思路 springmvc+mybaits的系统架构: 第一步:整合dao ...

  9. HDU1010(dfs+剪枝)

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  10. UVALIVE 3486 Cells

    通过入栈出栈顺序判断祖先关系 这里UVALIVE还 #include <map> #include <set> #include <list> #include & ...