bzoj4160: [Neerc2009]Exclusive Access 2
Description
Input
Output
Sample Input
P Q
Q R
R
P
Sample Output




#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的更多相关文章
- BZOJ.4160.[NEERC2009]Exclusive Access 2(状压DP Dilworth定理)
BZOJ DAG中,根据\(Dilworth\)定理,有 \(最长反链=最小链覆盖\),也有 \(最长链=最小反链划分数-1\)(这个是指最短的最长链?并不是很确定=-=),即把所有点划分成最少的集合 ...
- Bus,Exclusive access,memory attribute
指令LDREX,STREX是在armv6中新加的指令,配合AMBA3--AXI中的lock[1:0]信号. 在Atomic Access一节中是这么规定的:ARLOCK[1:0]/AWLOCK[1:0 ...
- ESOURCE_LOCKED - cannot obtain exclusive access to locked queue '2484_0_00163'
早上一运维同事说,一个报盘程序启动的时候报了"ESOURCE_LOCKED - cannot obtain exclusive access to locked queue '2484_0_ ...
- Exclusive access control to a processing resource
A data processing system is provided with multiple processors that share a main memory. Semaphore va ...
- 『Exclusive Access 2 dilworth定理 状压dp』
Exclusive Access 2 Description 给出 N 个点M 条边的无向图,定向得到有向无环图,使得最长路最短. N ≤ 15, M ≤ 100 Input Format 第一行一个 ...
- 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 ...
- uva1439 Exclusive Access 2
感觉这道题读题有点难..似乎和现实联系的比较密切1.每个process的两个资源可以顺序反一下2.p->q,q->s不可以同时进行 p->q,p->s可以 输出最长等待链输出每 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- 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 ...
随机推荐
- javaweb笔记4之httpservlet
1 httpservlet简介 service方法是Servlet的入口方法,调用servlet会首先调用service方法.在service方法中,会根据请求方式分别调用不同的doXXX方法.例如, ...
- Quartz的cronTrigger表达式
CronTrigger CronTriggers往往比SimpleTrigger更有用,如果您需要基于日历的概念,而非SimpleTrigger完全指定的时间间隔,复发的发射工作的时间表.CronTr ...
- Spring MVC返回对象JSON
@RestController 用于返回对象,会自动格式化为JSON @RequestMapping("/user2") public User2 user2(Mo ...
- iTunes 11.2更新下载:改善播客阅读
昨日,苹果公布了iTunes 11.2更新,新版别改善了播客阅读的方法,让用户能够在新的"未播映的"标签中疾速找到没有赏识的单集,其他功用包括主动删去现已播映的单集,并可在&quo ...
- [转] linux下的c/c++调试器gdb
PS:1. 断点C++类函数,用b 命名空间::类名::方法名 2. 编译参数一定要加-g,才可断点调试 http://www.cnblogs.com/xd502djj/archive/2012/08 ...
- Android开发ScrollView上下左右滑动事件冲突整理一(根据事件)
主要通过重写 onInterceptTouchEvent 事件来解决,代码如下: package com.cm.android.pad.view.itemView; import android.co ...
- ubuntu 连接 mssql <转>
转自 http://www.sendong.net/thread-90941-1-1.html 在linux下连接MSSQL,因为微软同志没有提供任何接口给开发人员,大约他们认为要用MSSQL的,只 ...
- Redis的AOF功能
引言: Redis是基于内存的数据库,同时也提供了若干持久化的方案,允许用户把内存中的数据,写入本地文件系统,以备下次重启或者当机之后继续使用.本文将描述如何基于Redis来设置AOF功能 什么是R ...
- 9.2noip模拟试题
题目名称 改造二叉树 数字对 交换 英文名称 binary pair swap 输入文件名 binary.in pair.in swap.in 输出文件名 binary.out pair.out ...
- MySQL中TIMESTAMP和DATETIME区别
1.两者的存储方式不一样 TIMESTAMP:把客户端插入的时间从当前时区转化为UTC(世界标准时间)进行存储.查询时,将其又转化为客户端当前时区进行返回. DATETIME:不做任何改变,基本上是原 ...