ural 1500 Pass Licenses (状态压缩+dfs)
1500. Pass Licenses
Memory limit: 64 MB
Input
Output
Sample
| input | output |
|---|---|
3 3 3 |
2 |
Problem Source: Quarter-Final of XXXI ACM ICPC - Yekaterinburg - 2006
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <utility>
#include <queue>
#include <stack>
#define set(s,x) (s|=(1<<x))
#define test(s,x) (s&(1<<x))
using namespace std;
const int INF=<<;
const double eps=1e-;
const int N = ; int cost[N][N];
int k,n,m;
bool vis[N]; bool dfs(int s,int u)
{
if(u==) return ;
if(vis[u]) return ;
vis[u]=;
for(int v=;v<n;v++)
{
if(u==v) continue;
if((cost[u][v]&s))
if(dfs(s,v))
return ;
}
return ;
} int getcnt(int s)
{
int i,cnt=;
for(i=;i<k;i++)
if(test(s,i))
cnt++;
return cnt;
} void print(int s)
{
for(int i=;i<k;i++)
if(test(s,i))
printf("%d ",i);
puts("");
} void run()
{
memset(cost,,sizeof(cost));
int u,v,w;
while(m--)
{
scanf("%d%d%d",&u,&v,&w);
if(u==v) continue;
set(cost[u][v],w);
set(cost[v][u],w);
}
int ans, anst = k+;
for(int i=;i<(<<k);i++)
{
memset(vis,,sizeof(vis));
int tmp = getcnt(i);
if(tmp>=anst) continue;
if(dfs(i,))
{
anst = tmp;
ans = i;
}
}
printf("%d\n",anst);
print(ans);
} int main()
{
#ifdef LOCAL
freopen("case.txt","r",stdin);
#endif
while(scanf("%d%d%d",&k,&n,&m)!=EOF)
run();
return ;
}
ural 1500 Pass Licenses (状态压缩+dfs)的更多相关文章
- SGU -1500 - Pass Licenses
先上题目: 1500. Pass Licenses Time limit: 2.5 secondMemory limit: 64 MB A New Russian Kolyan believes th ...
- hihocoder 1334 - Word Construction - [hiho一下第170周][状态压缩+DFS]
题目链接:https://hihocoder.com/problemset/problem/1334 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Given N wo ...
- HDU 1198 Farm Irrigation(状态压缩+DFS)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=1198 题目: Farm Irrigation Time Limit: 2000/1000 MS (Ja ...
- POJ-3279.Fliptile(二进制状态压缩 + dfs) 子集生成
昨天晚上12点刷到的这个题,一开始一位是BFS,但是一直没有思路.后来推了一下发现只需要依次枚举第一行的所有翻转状态然后再对每个情况的其它田地翻转进行暴力dfs就可以,但是由于二进制压缩学的不是很透, ...
- codeforces B - Preparing Olympiad(dfs或者状态压缩枚举)
B. Preparing Olympiad You have n problems. You have estimated the difficulty of the i-th one as inte ...
- 最大联通子数组之和(dfs,记忆化搜索,状态压缩)
最大联通子数组,这次的题目,我采用的方法为dfs搜索,按照已经取到的数v[][],来进行搜索过程的状态转移,每次对v[][]中标记为1的所有元素依次取其相邻的未被标记为1的元素,将其标记为1,然而,这 ...
- poj 1753 Flip Game(bfs状态压缩 或 dfs枚举)
Description Flip game squares. One side of each piece is white and the other one is black and each p ...
- UVA 1508 - Equipment 状态压缩 枚举子集 dfs
UVA 1508 - Equipment 状态压缩 枚举子集 dfs ACM 题目地址:option=com_onlinejudge&Itemid=8&category=457& ...
- uva10160(dfs+状态压缩)
题意:给出n个点,以及m条边,这些边代表着这些点相连,修一个电力站,若在某一点修一个站,那么与这个点相连的点都可以通电,问所有的点都通电的话至少要修多少个电力站........ 思路:最多给出的是35 ...
随机推荐
- yum 安装 mysql5.5 mysql 5.6 mysql5.7
一. yum 安装mysql5.6 1. 安装仓库 要使用yum 安装mysql,需要使用mysql的yum 仓库,先从官网下载适合你的系统仓库 http://dev.mysql.com/down ...
- 【BZOJ2406】矩阵 二分+有上下界的可行流
[BZOJ2406]矩阵 Description Input 第一行两个数n.m,表示矩阵的大小. 接下来n行,每行m列,描述矩阵A. 最后一行两个数L,R. Output 第一行,输出最小的答案: ...
- android菜鸟学习笔记13----Android控件(二) 自定义控件简单示例
有时候,可能觉得系统提供的控件太丑,就会需要自定义控件来实现自己想要的效果. 以下主要参考<第一行代码> 1.自定义一个标题栏: 系统自带的标题栏很丑,且没什么大的作用,所以我们之前会在o ...
- 九度OJ 1025:最大报销额 (01背包、DP)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4352 解决:1055 题目描述: 现有一笔经费可以报销一定额度的发票.允许报销的发票类型包括买图书(A类).文具(B类).差旅(C ...
- The Log-Structured Merge-Tree (LSM-Tree
https://www.cs.umb.edu/~poneil/lsmtree.pdf [Log-Structured Merge-Tree ][结构化日志归并树][要解决的问题]The Log-S ...
- js实现网页中的"运行代码"功能
<!DOCTYPE html> <html> <head> <meta charset='utf8' /> <title>网页中的运行代码功 ...
- 【windows】如何让一个程序开机自启动
windows的开机自启动也是将一个程序放在文件夹下即可,将应用程序或者快捷方式放在如下文件夹下,即可实现开机自启动 C:\ProgramData\Microsoft\Windows\Start Me ...
- Spring Boot2.0之 jar打包方式
Jar类型打包方式 1.使用mvn celan package 打包 2.使用java –jar 包名 war类型打包方式 1.使用mvn celan package 打包 2.使用java –ja ...
- C++配置Opencv
https://blog.csdn.net/qq_17550379/article/details/78201442
- html5 手写的canvas实现
试用支持canvas的浏览器,无JS依赖,运用新的HTML5技术DrawBoard.renderDrawer('myHandWrite',{ penColor:'#FF0000', penWidt ...