UVA 10160 Servicing Stations(状态压缩+迭代加深)
【题目链接】 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(状态压缩+迭代加深)的更多相关文章
- uva 10160 Servicing Stations(DFS+剪枝)
Servicing stations A company offers personal computers for sale in N towns (3 <= N <= 35). The ...
- UVA 10160 Servicing Stations(深搜 + 剪枝)
Problem D: Servicing stations A company offers personal computers for sale in N towns (3 <= N < ...
- UVA - 11214 Guarding the Chessboard(迭代加深搜索)
题目: 输入一个n*m的棋盘(n,m<10),某些格子有标记,用最少的皇后守卫(即占据或攻击)所有的标记的格子.输出皇后的个数. 思路: 一开始没有想到用迭代加深搜索,直接dfs结果还没写完就发 ...
- UVA 1508 - Equipment dp状态压缩
题意: 已知n个5元组,从中选出k组,使得这些组中5个位置,每个位置上最大数之和最大. 分析:当k>5时,就是n个5元组最大的数之和,当k<5时,就当做5元组,状态压缩,用00000表示 ...
- UVA 11464 - Even Parity 状态压缩,分析 难度: 2
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- UVA 10651 Pebble Solitaire 状态压缩dp
一开始还在纠结怎么表示一个状态,毕竟是一个串.后来搜了一下题解发现了这里用一个整数的前12位表示转态就好了 ,1~o,0~'-',每个状态用一个数来表示,然后dp写起来就比较方便了. 代码: #inc ...
- UVA 11825 - Hackers' Crackdown 状态压缩 dp 枚举子集
UVA 11825 - Hackers' Crackdown 状态压缩 dp 枚举子集 ACM 题目地址:option=com_onlinejudge&Itemid=8&page=sh ...
- uva 11195 Another queen (用状态压缩解决N后问题)
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 1508 - Equipment 状态压缩 枚举子集 dfs
UVA 1508 - Equipment 状态压缩 枚举子集 dfs ACM 题目地址:option=com_onlinejudge&Itemid=8&category=457& ...
随机推荐
- 如何记录MySQL执行过的SQL语句
很多时候,我们需要知道 MySQL 执行过哪些 SQL 语句,比如 MySQL 被注入后,需要知道造成什么伤害等等.只要有 SQL 语句的记录,就能知道情况并作出对策.服务器是可以开启 MySQL 的 ...
- Codeforces Round #524 (Div. 2) C. Masha and two friends
C. Masha and two friends 题目链接:https://codeforc.es/contest/1080/problem/C 题意: 给出一个黑白相间的n*m的矩阵,现在先对一个子 ...
- maven与gradle的对比
Java世界中主要有三大构建工具:Ant.Maven和Gradle.经过几年的发展,Ant几乎销声匿迹.Maven也日薄西山,而Gradle的发展则如日中天.笔者有幸见证了Maven的没落和Gradl ...
- ServletContext 接口读取配置文件要注意的路径问题
在建立一个maven项目时,我们通常把一些文件直接放在resource下面,在ServletContext中有getResource(String path)和getResourceAsStream( ...
- 转:强化学习(Reinforcement Learning)
机器学习算法大致可以分为三种: 1. 监督学习(如回归,分类) 2. 非监督学习(如聚类,降维) 3. 增强学习 什么是增强学习呢? 增强学习(reinforcementlearning, RL)又叫 ...
- 51Nod 1212无向图最小生成树
prim #include<stdio.h> #include<string.h> #define inf 0x3f3f3f3f ][]; ],lowc[]; ],int n) ...
- codechef T2 Chef and Sign Sequences
CHEFSIGN: 大厨与符号序列题目描述 大厨昨天捡到了一个奇怪的字符串 s,这是一个仅包含‘<’.‘=’和‘>’三种比较符号的字符串. 记字符串长度为 N,大厨想要在字符串的开头.结尾 ...
- bzoj 2142 国家集训队试题 礼物
问题转化成求C(N,M) mod P p为非素数,那么我们可以将P分解质因数, 也就是 π pi^ci的形式,因为这些pi^ci是互质的,所以我们可以用crt将他们合并 那么问题就转化成了快速求C(N ...
- 如何完全禁用或卸载Windows 10中的OneDrive
该功能占用很大的内存与CPU 详见http://os.51cto.com/art/201508/489371.htm
- Swift : missing argument label 'xxx' in call
http://stackoverflow.com/questions/24050844/swift-missing-argument-label-xxx-in-call up vote37down v ...