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. javaweb笔记5之请求编码问题

    post提交: 设置实体内容的编码:request.setCharacterEncoding("utf-8"); 注意:一定要在获取所有参数之前设置,否则设置无效! get方式提交 ...

  2. Linux 和 Windows 下对long long的输出

    以前一直用__int64来识别windows还是Linux,可是发现HDU好像不认 看到wzy用的UNIX可以. UNIX是Linux下定义的,具体是什么可以去百度. 那么就可以 #ifdef UNI ...

  3. Java学习的随笔(3)接口

    首先是一段<Java编程思想>中,对接口的解释:“interface这个关键字产生一个完全抽象的类,它根本就没有提供任何具体的实现.它允许创建者确定方法名.参数列表.返回类型,但是没有任何 ...

  4. Unity3D 画线插件 Vectrosity 画一个一直循环的正弦函数曲线

    直接贴代码 public Material myMaterisl; float fx;//曲线最左边的X坐标 float fy;//曲线趋于直线时y轴坐标 float fyMax = 0f;//曲线最 ...

  5. C++ 求阶乘 四种方法

    来总结下求阶乘的各种方法哈. 写在最前:①各个代码仅仅是提供了求阶乘的思路,以便在实际须要时再来编码,代码并不健壮!②各个程序都在1到10内測试正确. 代码一: #include<iostrea ...

  6. vim note(4)

    :new 文件名.词尾 新文件. :e 文件名 打开文件. :w 文件名.txt 保存文件. :wq 保存并退出. :x 辍学.假设文件更改被保存 版权声明:本文博主原创文章,博客,未经同意不得转载.

  7. Linux 监控CPU 温度

      安装测试系统: 硬件:普通PC机, 软件:redhat linux as 4  2.6 .9 , 安装系统自带的lm_sensors-2.8.7-2.i386 你也可以从[url]http://w ...

  8. Windows与Linux文件共享

    Windows与Linux文件共享 Samba服务器 安装Samba服务器 rpm –ivh /mnt/Packages/Samba-3.5.10-125.el6.i686.rpm 添加用户并修改密码 ...

  9. HUD 2444 The Accomodation of Students (二分图染色+最大匹配)

    #include<iostream> #include<cstdio> #include<cstring> #define maxn 2010 using name ...

  10. Java 8 Lambda表达式10个示例【存】

    PS:不能完全参考文章的代码,请参考这个文件http://files.cnblogs.com/files/AIThink/Test01.zip 在Java 8之前,如果想将行为传入函数,仅有的选择就是 ...