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. apache POI 导出excel相关方法

    apache POI 操作excel无比强大.同时有操作word和ppt的接口. 下面讲解poi中常用方法. 1,设置列宽 HSSFSheet sheet = wb.getSheetAt(0); sh ...

  2. Android数据存储(1)少量数据保存之SharedPreferences接口实例

    SharedPreferences数据保存主要是通过键值的方式存储在xml文件中 xml文件在data/此程序的包名/XX.xml 格式 <?xml version='1.0' encoding ...

  3. 让你的WizFi250适应各种气候

    这篇文章会具体描写叙述如何马上得到指定城市的天气状况(比方首尔).由OpenWeatherMap提供. 用JSON(由OpenWeatherMap提供),XML和一个以太网模块.使WIZnet-Wiz ...

  4. Java Applet读写client串口——终极篇

    測试环境: SDK:Oracle JRockit for Java version 6, Java Communication for Windows 2.0 OS:WINDOWS7 外设:串口条形码 ...

  5. MYSQL 体系结构图-unzip_LRU

  6. select poll epoll三者之间的比较

    一.概述 说到Linux下的IO复用,系统提供了三个系统调用,分别是select poll epoll.那么这三者之间有什么不同呢,什么时候使用三个之间的其中一个呢? 下面,我将从系统调用原型来分析其 ...

  7. 详解Android Handler的使用-别说你不懂handler(转)

    我们进行Android开发时,Handler可以说是使用非常频繁的一个概念,它的用处不言而喻.本文就详细介绍Handler的基本概念和用法. Handler的基本概念         Handler主 ...

  8. linux (ubuntu) 下设置 tomcat 随系统自动启动

    网上说的有很多, 我只记录一种 1. 切换到 /etc/init.d/ 目录下 2. sudo vim tomcat 3. 在打开的文件里写入以下内容 #!/bin/sh # chkconfig: # ...

  9. 排名最重要的三个优化阶段分析 --------------------->>转至(卧牛SEO/武汉SEO http://blog.sina.com.cn/zhengkangseo )

    网站排名,不是一两天能够决定的.要想取得好的排名,得分时间分阶段地做排名,网站优化分前期,中期,后期,怎么来区别不同的阶段该用怎样的优化手段.今晚SEO研究中心创始人Moon老师分享:排名最重要的三个 ...

  10. (转)Css样式兼容IE6,IE7,FIREFOX的写法

    根据FF和IE对一些符号识别的差异,我们可以单独对FF以及IE定义样式,例子: 区别IE6与FF:          background:orange;*background:blue;   区别I ...