Description

给出 N 个点M 条边的无向图,定向得到有向无环图,使得最长路最短。
N ≤ 15, M ≤ 100

Input

第一行一个数M (1≤M≤100).
接下来M行,每行两个大写字母(L 到 Z),最多出线15个不同的大写字母。每行的两个大写字母不会相同

Output

第一行输出最长路最短的数值-1。
 

Sample Input

3
P Q
Q R
R
P

Sample Output

1
 
 
 
 
 #include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#define inf 1061109567
using namespace std;
char a[],b[];
int n,m,u,v,cnt,pos[],g[][],can[<<],f[<<],list[];
int calc(int cnt){
if (f[cnt]<inf) return f[cnt];
int ans=inf,ncnt=cnt;
while (ncnt){
if (can[ncnt]) ans=min(ans,calc(cnt^ncnt)+);
ncnt=(ncnt-)&cnt;
}
return f[cnt]=ans;
}
int main(){
scanf("%d",&m);
memset(pos,-,sizeof(pos));
for (int i=;i<=m;i++){
scanf("%s%s",a,b),u=a[]-'L',v=b[]-'L';
if (pos[u]==-) pos[u]=n++;
if (pos[v]==-) pos[v]=n++;
g[pos[u]][pos[v]]=g[pos[v]][pos[u]]=;
}
for (int i=;i<(<<n);i++){
cnt=,can[i]=;
for (int j=;j<n;j++) if (i&(<<j)) list[++cnt]=j;
for (int a=,u=list[a];a<=cnt&&can[i];u=list[++a])
for (int b=,v=list[b];b<=cnt&&can[i];v=list[++b])
if (g[u][v]) can[i]=;
}
memset(f,,sizeof(f));
f[]=;
printf("%d\n",calc((<<n)-)-);
return ;
}

bzoj4160: [Neerc2009]Exclusive Access 2的更多相关文章

  1. BZOJ.4160.[NEERC2009]Exclusive Access 2(状压DP Dilworth定理)

    BZOJ DAG中,根据\(Dilworth\)定理,有 \(最长反链=最小链覆盖\),也有 \(最长链=最小反链划分数-1\)(这个是指最短的最长链?并不是很确定=-=),即把所有点划分成最少的集合 ...

  2. Bus,Exclusive access,memory attribute

    指令LDREX,STREX是在armv6中新加的指令,配合AMBA3--AXI中的lock[1:0]信号. 在Atomic Access一节中是这么规定的:ARLOCK[1:0]/AWLOCK[1:0 ...

  3. ESOURCE_LOCKED - cannot obtain exclusive access to locked queue '2484_0_00163'

    早上一运维同事说,一个报盘程序启动的时候报了"ESOURCE_LOCKED - cannot obtain exclusive access to locked queue '2484_0_ ...

  4. Exclusive access control to a processing resource

    A data processing system is provided with multiple processors that share a main memory. Semaphore va ...

  5. 『Exclusive Access 2 dilworth定理 状压dp』

    Exclusive Access 2 Description 给出 N 个点M 条边的无向图,定向得到有向无环图,使得最长路最短. N ≤ 15, M ≤ 100 Input Format 第一行一个 ...

  6. InvalidOperationException: Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's

    InvalidOperationException: Operations that change non-concurrent collections must have exclusive acc ...

  7. uva1439 Exclusive Access 2

    感觉这道题读题有点难..似乎和现实联系的比较密切1.每个process的两个资源可以顺序反一下2.p->q,q->s不可以同时进行 p->q,p->s可以 输出最长等待链输出每 ...

  8. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  9. embody the data item with the ability to control access to itself

    Computer Science An Overview _J. Glenn Brookshear _11th Edition Such communication needs have long b ...

随机推荐

  1. 2012蓝桥杯本科组C/C++预赛题

    微生物增殖 假设有两种微生物 X 和 Y X出生后每隔3分钟分裂一次(数目加倍),Y出生后每隔2分钟分裂一次(数目加倍). 一个新出生的X,半分钟之后吃掉1个Y,并且,从此开始,每隔1分钟吃1个Y. ...

  2. .net core4

  3. winform combobox控件绑定 分类: WinForm 2014-04-17 14:34 118人阅读 评论(0) 收藏

    想要达到的效果:把数据库中的一列数据绑定到combobox控件中. 数据库表:T_Task//任务表 列名:Task_Name//名称 主键:Task_ID combobox控件名称:cbName 解 ...

  4. 如何调试delphi的Access violation at address错误

    1.什么是 MAP 文件?简单地讲,MAP 文件是程序的全局符号.源文件和代码行号信息的唯一的文本表示方法,它可以在任何地方.任何时候使用,不需要有额外的程序进行支持. 2.DELPHI下生成MAP文 ...

  5. axf、elf文件转换成bin、hex脚本工具

    在嵌入式开发过程中常常遇到将axf或elf文件转换成bin的情况,大家都知道通过gnu toolchain中的objcopy和keil中的fromelf能做到.可是为了这么一个小事而记住复杂的选项以及 ...

  6. Android 使用加速度传感器实现摇一摇功能及优化

    如有转载,请声明出处: 时之沙: http://blog.csdn.net/t12x3456 目前很多应用已经实现了摇一摇功能,这里通过讲解该功能的原理及实现回顾一下加速度传感器的使用: 1.首先获得 ...

  7. PHP简单利用token防止表单重复提交(转)

    <?php/* * PHP简单利用token防止表单重复提交 */function set_token() { $_SESSION['token'] = md5(microtime(true)) ...

  8. HDU 5211 筛法求约数

    给出n个数a1,a2...an,定义函数 f[i]=j,(i<j),表示aj mod ai=0 的最小j,其中j大于i,如果不存在这样的数,则f[i]=0 求n个数所有f[]值的和 先用筛法o( ...

  9. border属性妙用

    以前只知道border属性是盒模型中的边框属性,一直不清楚每个边的border是矩形拼接有重合呢,还是梯形无缝拼接的. border梯形 为了观察边框究竟是哪一种拼接方式,为边框设置不同的颜色背景,代 ...

  10. webApp禁止用户保存图像

    img { -webkit-touch-callout: none; }