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 ...
随机推荐
- EasyNVR流媒体服务器接入EasyDSS云视频平台快照上传实现
EasyNVR拥有接入EasyDSS云平台的功能 接入EasyDSS云平台会定时向云平台上传快照数据,这个快照数据用于云平台向客户端提供快照展示 遇到的问题 由于快照上传的间隔提供认为修改的功能,则我 ...
- wxPython的Refresh与事件双重响应
#!/usr/bin/env python import wx class DoubleEventFrame(wx.Frame): def __init__(self, parent, id): wx ...
- 【题解】P3939数颜色
[题解]P3939 数颜色 不要数据结构和模板学傻了... 考虑到兔子们交换都是相邻的,说明任何一次交换只会引起\(O(1)\)的变化. 我们开很多\(vector\)存没种兔子的下标就好了.到时候二 ...
- Flask:工厂函数和蓝本
我们用pycharm去新建Flask项目的时候,会默认生成开发文件.如下,其中包括static,templates,flask1_prj.py文件 在最初开始的时候,我们的app等声明都是在flask ...
- python cookbook第三版学习笔记四:文本以及字符串令牌解析
文本处理: 假设你存在一个目录,下面存在各种形式的文件,有txt,csv等等.如果你只想找到其中一种或多种格式的文件并打开该如何办呢.首先肯定是要找到满足条件的文件,然后进行路径合并在一一打开. pa ...
- 【zabbix】Windows服务器获取IIS站点以及程序池状态
在使用zabbix做Windows服务器监控的时候遇到一个比较棘手的问题,检测IIS站点状态. 普通情况下,只要用浏览器访问iis站点测试一下返回码是不是200即可判断状态,但是我这次遇到的是iis使 ...
- [IR课程笔记]Hyperlink-Induced Topic Search(HITS)
两个假设 1. 好的hub pages: 好的对某个主题的hub pages 链接许多好的这个主题的authoritative pages. 2. 好的authoritative pages: 好的对 ...
- 剑指Offer:二叉树中和为某一值的路径【34】
剑指Offer:二叉树中和为某一值的路径[34] 题目描述 输入一颗二叉树和一个整数,打印出二叉树中结点值的和为输入整数的所有路径.路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路径. ...
- openstack多region介绍与实践
版权声明:本文为原创文章,转载请注明出处. 概念介绍 所谓openstack多region,就是多套openstack共享一个keystone和horizon.每个区域一套openstack环境,可以 ...
- POJ 1330 Nearest Common Ancestors 【最近公共祖先LCA算法+Tarjan离线算法】
Nearest Common Ancestors Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 20715 Accept ...