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. hdu 4579 博弈+区间dp

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4597 #include <cstdio> #include <cstring> ...

  2. Struts2学习笔记之s:select标签

    貌似Struts2 标签都快忘光了  今天先来一发struts2的select标签: 首先从简到难,静态赋值: 1 <s:select name="user.sex" lis ...

  3. 提升ReSharper和Visual Studio的性能

    转载 作者:赵青青        出处:http://www.cnblogs.com/zhaoqingqing/ 文章目录[点击展开](?)[+]   提升性能 我们不断地确保ReSharper的正常 ...

  4. Sublime 注册码

    ----- BEGIN LICENSE ----- Andrew Weber Single User License EA7E-855605 813A03DD 5E4AD9E6 6C0EEB94 BC ...

  5. cocos2d-x 3.0 利用python脚本在文件夹Classes内创建class

    因为VS2012创建默认文件是在proj.win32下,新建类不在VS的classes于是编译时找不到类.直接写个脚本帮助新建类(cpp和h文件),还能够在里面加上一些预先写好的代码. 批处理文件Cr ...

  6. [转] 使用CodeViz生成C/C++函数调用关系图

    运行环境:虚拟机下的Ubuntu 11.04 结合Graphviz工具,使用CodeViz可以生成直观和漂亮的C/C++程序函数之间的调用关系图. 1.安装graphviz 在安装CodeViz之前, ...

  7. 模板-->Matrix重载运算符:+,-,x

    如果有相应的OJ题目,欢迎同学们提供相应的链接 相关链接 所有模板的快速链接 poj_2118_Firepersons,my_ac_code 简单的测试 INPUT: 1 2 3 1 3 4 3 -1 ...

  8. Ouath协议

    OAuth是一个开放协议,允许用户让第三方应用以安全且标准的方式获取该用户在某一网站.移动或桌面应用上存储的私密的资源(如用户个人信息.照片.视频.联系人列表),而无需将用户名和密码提供给第三方应用. ...

  9. Android客户端与服务端交互之登陆示例

    Android客户端与服务端交互之登陆示例 今天了解了一下android客户端与服务端是怎样交互的,发现其实跟web有点类似吧,然后网上找了大神的登陆示例,是基于IntentService的 1.后台 ...

  10. 关于JS中查看当前节点的兄弟节点的使用

    <tr> <td align="center"><input style="width: 20px;" type="ch ...