1139: [POI2009]Wie

https://www.lydsy.com/JudgeOnline/problem.php?id=1139

分析:

  Dijkstra。状压最短路,dis[i][j]表示到第i个点,状态为j的最短路。

  或者 分层最短路可以做。

代码:

 #include<bits/stdc++.h>
using namespace std;
typedef long long LL; inline int read() {
int x=,f=;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
for(;isdigit(ch);ch=getchar())x=x*+ch-'';return x*f;
} const int N = ;
const int M = ; int dis[][], head[N], to[M<<], nxt[M<<], sta[M<<], len[M<<], S[N], Enum, n;
bool vis[][]; struct Heap{
int u, dis, st;
Heap() {}
Heap(int a,int b,int c) {u = a, dis = b, st = c;}
bool operator < (const Heap &A) const {
return dis > A.dis;
}
};
priority_queue < Heap > q; void add_edge(int u,int v,int w,int s) {
++Enum; to[Enum] = v; len[Enum] = w; sta[Enum] = s; nxt[Enum] = head[u]; head[u] = Enum;
++Enum; to[Enum] = u; len[Enum] = w; sta[Enum] = s; nxt[Enum] = head[v]; head[v] = Enum;
} int Dijkstra() {
memset(dis, 0x3f, sizeof(dis));
dis[][] = ;
q.push(Heap(, , ));
while (!q.empty()) {
int d = q.top().dis, u = q.top().u, s = q.top().st; q.pop();
if (u == n) return d;
if (vis[u][s]) continue;
vis[u][s] = true;
s |= S[u];
for (int i=head[u]; i; i=nxt[i]) {
int v= to[i];
if ((sta[i] | s) != s) continue;
if (dis[v][s] > d + len[i]) {
dis[v][s] = d + len[i];
q.push(Heap(v, dis[v][s], s));
}
}
}
return -;
} int main () { n = read(); int m = read(), p = read(), k = read();
for (int w,cnt,t,st,i=; i<=k; ++i) {
w = read(), cnt = read();
for (int j=; j<=cnt; ++j) {
t = read();
S[w] |= ( << (t - ));
}
}
for (int i=; i<=m; ++i) {
int u = read(), v = read(), w = read(), cnt = read(), st = , t;
for (int j=; j<=cnt; ++j) {
t = read();
st |= ( << (t - ));
}
add_edge(u, v, w, st);
}
printf("%d",Dijkstra());
return ;
}

1139: [POI2009]Wie的更多相关文章

  1. [POI2009]Wie

    题目 BZOJ 虽然是解压题但也学到了简洁的码风 做法 \(dijkstra\)跑动规 My complete code #include<bits/stdc++.h> #include& ...

  2. bzoj1139:[POI2009]Wie

    传送门 状压dp,最短路 spfa似乎特别慢 代码: #include<cstdio> #include<iostream> #include<algorithm> ...

  3. bzoj AC倒序

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

  4. BZOJ 1115: [POI2009]石子游戏Kam

    1115: [POI2009]石子游戏Kam Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 883  Solved: 545[Submit][Stat ...

  5. BZOJ 4384: [POI2015]Trzy wieże

    4384: [POI2015]Trzy wieże Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 217  Solved: 61[Submit][St ...

  6. BZOJ 1142: [POI2009]Tab

    1142: [POI2009]Tab Time Limit: 40 Sec  Memory Limit: 162 MBSubmit: 213  Solved: 80[Submit][Status][D ...

  7. URAL 1139 City Blocks(数论)

    The blocks in the city of Fishburg are of square form. N avenues running south to north and Mstreets ...

  8. 【BZOJ】【1115】【POI2009】石子游戏KAM

    博弈论 这个题……一看就觉得很捉急啊= =肿么办? 灵光一现:差分一下~ 那么我们看一下差分以后,从第 i 堆中拿走 k 个石子变成了:a[i]-=k; a[i+1]+=k; 嗯这就转化成了阶梯博弈! ...

  9. bzoj 1133: [POI2009]Kon dp

    1133: [POI2009]Kon Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 242  Solved: 81[Submit][Status][D ...

随机推荐

  1. linux下安装jdk和配置环境变量

    参考博文:http://www.cnblogs.com/samcn/archive/2011/03/16/1986248.html 系统环境:linux centos 6.4_x64 软件版本:jdk ...

  2. 【洛谷P1288】取数游戏II

    取数游戏II 题目链接 显然,由于一定有一个0,我们可以求出从初始点到0的链的长度 若有一条链长为奇数,则先手可以每次取完一条边上所有的数, 后手只能取另一条边的数,先手必胜: 反之若没有奇数链,后手 ...

  3. 【luogu P3627 [APIO2009]抢掠计划】 题解

    题目链接:https://www.luogu.org/problemnew/show/P3627 把点权转化到边权上去. #include <stack> #include <que ...

  4. Android学习笔记_60_Android常用ADB命令

    第一部分: 1. ubuntu下配置环境anroid变量: 在终端执行 sudo gedit /etc/profile 打开文本编辑器,在最后追加#set android environment 2. ...

  5. 旧文备份:FFTW介绍

    1. FFTW介绍 FFTW由麻省理工学院计算机科学实验室超级计算技术组开发的一套离散傅立叶变换(DFT)的计算库,开源.高效和标准C语言编写的代码使其得到了非常广泛的应用,Intel的数学库和Sci ...

  6. triplet loss

    因为待遇低,因为工作不开心,已经严重影响了自己的工作积极性和工作效率,这几天发觉这样对自己实在是一种损失,决定提高工作效率,减少工作时间. 说说最近做的tracking, multi-object t ...

  7. Restrramework源码(包含组件)分析

    1.总体流程分析 rest_framework/view.py 请求通过url分发,触发as_view方法,该方法在ViewSetMixin类下 点进去查看as_view源码说明,可以看到它在正常情况 ...

  8. (mybatis)There is no getter for property named 'isEffective' in 'class java.lang.String

    原来代码: <select id="findSpecialOffer" resultType="com.lizard.back.model.SpecialOffer ...

  9. java.util.ArrayList,java.util.LinkedList,java.util.Vector的区别,使用场合.

    下图是Collection的类继承图 从图中可以看出:Vector.ArrayList.LinkedList这三者都实现了List 接口.所有使用方式也很相似,主要区别在于实现方式的不同,所以对不同的 ...

  10. IDEA中解决Edit Configurations中没有tomcat Server选项的问题(附配置Tomcat)

    1.点击File-->settings(Ctrl+Alt+S) 2.在弹出的窗口中的搜索框中输入appliation,然后选择下方的Plugins,再然后勾选左侧Installed中的如图所示的 ...