SGU -1500 - Pass Licenses
先上题目:
1500. Pass Licenses
Memory limit: 64 MB
Input
Output
Sample
| input | output |
|---|---|
3 3 3 |
2 |
题意:给出n个点m条边(无向),有k种驾照,每条边如果想通过的话需要某一种驾照,问你从0号点到1号点最少需要多少种驾照,并把它们输出。
做法:状态压缩然后暴力检查是否合法,记录最少需要多少中驾照。
s[i][j]表示从i->j的话有哪几种可以用的驾照。然后枚举不同的驾照组合,找到最少需要的数目以后输出即可。
上代码:
#include <cstdio>
#include <cstring>
#include <utility>
#include <set>
#define MAX 32
#define MK(x,y) (make_pair(x,y))
using namespace std; int s[MAX][MAX];
bool vis[MAX];
int k,n,m; bool dfs(int u,int caps) {
vis[u]=;
if(u==) return ;
for(int i=;i<n;i++){
if(!vis[i] && (caps&s[u][i])){
if(dfs(i,caps)) return ;
}
}
return ;
} int main() {
int u,v,cap,ans,caps,f;
//freopen("data.txt","r",stdin);
while(scanf("%d %d %d",&k,&n,&m)!=EOF) {
memset(s,,sizeof(s));
for(int i=;i<m;i++){
scanf("%d %d %d",&u,&v,&cap);
if(u==v) continue;
s[u][v]|=(<<cap);
s[v][u]|=(<<cap);
}
ans=k+;
caps=;
for(int i=;i<(<<k);i++){
int cnt=;
for(int j=;j<k;j++){
if(i&(<<j)) cnt++;
}
if(cnt>=ans) continue;
memset(vis,,sizeof(vis));
if(dfs(,i)){
ans=cnt;
caps=i;
}
}
printf("%d\n",ans);
f=;
for(int i=;caps>;caps>>=,i++){
if(caps&){
if(f++) printf(" ");
printf("%d",i);
}
}
printf("\n");
}
return ;
}
/*SGU 1500*/
SGU -1500 - Pass Licenses的更多相关文章
- ural 1500 Pass Licenses (状态压缩+dfs)
1500. Pass Licenses Time limit: 2.5 secondMemory limit: 64 MB A New Russian Kolyan believes that to ...
- BZOJ 1500/Luogu 2042 - 维修数列 - [NOI2005][Splay]
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1500 题目链接:https://www.luogu.org/problemnew/sho ...
- [模拟电路] 2、Passive Band Pass Filter
note: Some articles are very good in http://www.electronics-tutorials.ws/,I share them in the Cnblog ...
- Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' heade
XMLHttpRequest cannot load http://10.164.153.37:8050/WebService/WebService.asmx/wsGetStreetData. Res ...
- UvaLA 3938 "Ray, Pass me the dishes!"
"Ray, Pass me the dishes!" Time Limit: 3000MS Memory Limit: Unkn ...
- 解决服务器每次都要输入Enter PEM pass phrase
今天架设好Python的HTTPS云服务器, 发现每次连接都要Enter PEM pass phrase 把服务器端的key里面的key剥离掉就好了 openssl rsa -in server.ke ...
- SQL Pass北京举行2014年第一次线下活动
地点:北京微软(中国)有限公司[望京利星行],三层308室 时间:2014年 3 月15日 13:30-16:30 SQL PASS 北京QQ群号:2435349 报名地址:http://1drv.m ...
- SQL Pass北京举办1周年活动(本次活动特别邀请到了来自微软的SQL Server大师何雷谈数据库职业规划)
地点:北京微软(中国)有限公司[望京利星行],三层308室 时间:2013年 12 月28日 13:30-16:30 SQL PASS 北京QQ群号:2435349 新浪微群地址:http://q.w ...
- SQL Pass北京举办第11次线下活动,欢迎报名(本次活动特别邀请了来自微软总部Xin Jin博士)
活动主题: 探讨SQL Server 2014与Fusion IO在SQL Server中的应用 地点:北京微软(中国)有限公司[望京利星行],三层308室 时间:2013年 10 月19日 13:3 ...
随机推荐
- 1617: [Usaco2008 Mar]River Crossing渡河问题(dp)
1617: [Usaco2008 Mar]River Crossing渡河问题 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1219 Solved: ...
- ECMA里面的一元符
只能操作一个值的叫做一元操作符.一元操作符是ECMAScript中最简单的操作符 1.递增和递减操作符 递增和递减操作符直接借鉴自c,而且各有俩个版本,前置型和后置型.顾名思义,前置型就是位于要操作的 ...
- spring cloud config搭建说明例子(二)-添加eureka
添加注册eureka 服务端 ConfigServer pom.xml <dependency> <groupId>org.springframework.cloud</ ...
- 组合数学题 Codeforces Round #108 (Div. 2) C. Pocket Book
题目传送门 /* 题意:每一次任选i,j行字符串进行任意长度前缀交换,然后不断重复这个过程,问在过程中,第一行字符串不同的个数 组合数学题:每一列不同的字母都有可能到第一行,所以每列的可能值相乘取模就 ...
- Android 性能优化(23)*性能工具之「Heap Viewer, Memory Monitor, Allocation Tracker」Memory Profilers
Memory Profilers In this document Memory Monitor Heap Viewer Allocation Tracker You should also read ...
- java 选择排序与冒泡排序
选择排序与冒泡排序的特点与区别 ++++++++++++++++++++++++++++++++++++++++++++++ 选择排序 这一种简单的排序方法,它的基本思想是:R[n]第一次从R[0]~ ...
- EasyUI系列学习(七)-Linkbutton(按钮)
一.加载组件 1.使用class加载 <a href="#" class="easyui-linkbutton">按钮</a> 2.使用 ...
- Thread stack overrun
ERROR 1436 (HY000): Thread stack overrun: 6448 bytes used of a 131072 byte stac k, and 128000 bytes ...
- 远程图形界面:使用putty+xmin远程登录ubuntu-kde
让我继续用反人类的编辑器Vim和emacs,我宁愿自断三指.因此,在Win端配置WinSCP+Putty+Xming远程操作ubuntu. 参考链接:putty+xming远程登录Ubuntu16.0 ...
- HDU_1024_dp
Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...