1139: [POI2009]Wie
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的更多相关文章
- [POI2009]Wie
题目 BZOJ 虽然是解压题但也学到了简洁的码风 做法 \(dijkstra\)跑动规 My complete code #include<bits/stdc++.h> #include& ...
- bzoj1139:[POI2009]Wie
传送门 状压dp,最短路 spfa似乎特别慢 代码: #include<cstdio> #include<iostream> #include<algorithm> ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- BZOJ 1115: [POI2009]石子游戏Kam
1115: [POI2009]石子游戏Kam Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 883 Solved: 545[Submit][Stat ...
- BZOJ 4384: [POI2015]Trzy wieże
4384: [POI2015]Trzy wieże Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 217 Solved: 61[Submit][St ...
- BZOJ 1142: [POI2009]Tab
1142: [POI2009]Tab Time Limit: 40 Sec Memory Limit: 162 MBSubmit: 213 Solved: 80[Submit][Status][D ...
- URAL 1139 City Blocks(数论)
The blocks in the city of Fishburg are of square form. N avenues running south to north and Mstreets ...
- 【BZOJ】【1115】【POI2009】石子游戏KAM
博弈论 这个题……一看就觉得很捉急啊= =肿么办? 灵光一现:差分一下~ 那么我们看一下差分以后,从第 i 堆中拿走 k 个石子变成了:a[i]-=k; a[i+1]+=k; 嗯这就转化成了阶梯博弈! ...
- bzoj 1133: [POI2009]Kon dp
1133: [POI2009]Kon Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 242 Solved: 81[Submit][Status][D ...
随机推荐
- 人多qiu是好
小组第一次冲刺 团队任务描述: 在确定完分组,并对于敏捷开发做了相应的了解之后,我们团队开始了第一次的冲刺.对于我们团队的第一次的Scrum冲刺,我们团队开展了团队会议.首先,我们明确了我们的目标,对 ...
- Error: Error SSL Required Code: 403
Error: Error SSL Required Code: 403 Error Message If the 'services' Web directory for ArcGIS is set ...
- 【BZOJ4573】[ZJOI2016] 大森林(LCT)
点此看题面 大致题意: 有\(n\)棵树,初始各有\(1\)个编号为\(1\)的节点,且其为生长节点.\(3\)种操作:将\([l,r]\)区间内的树增加一个新的编号的节点,修改\([l,r]\)区间 ...
- 论文笔记:Progressive Differentiable Architecture Search:Bridging the Depth Gap between Search and Evaluation
Progressive Differentiable Architecture Search:Bridging the Depth Gap between Search and Evaluation ...
- axis调用cxf的webservice注意事项
需要注意的是: 1.wsdl显示部分内容 <?xml version="1.0" ?> - <wsdl:definitions name="Archiv ...
- 【luogu P2863 [USACO06JAN]牛的舞会The Cow Prom】 题解
题目链接:https://www.luogu.org/problemnew/show/P2863 求强连通分量大小>自己单个点的 #include <stack> #include ...
- Java中关于String的比较
关于String的各种==和equals,有的人搞不懂 简而言之 String s1 = "Hello" 声明的是一个常量,会在常量池里. ...
- 使用Dapper处理多个结果集和多重映射的教程
在本文中,我们将介绍如何使用DAPPER从单个数据库调用中读取数据库中的多个结果集.我们将看看我们可能希望这样做的场景,以及如何使用它的Query和QueryMultiple方法更简洁地实现这一点. ...
- 核心动画(UIView封装动画)-转
一.UIView动画(首尾) 1.简单说明 UIKit直接将动画集成到UIView类中,当内部的一些属性发生改变时,UIView将为这些改变提供动画支持. 执行动画所需要的工作由UIView类自动完成 ...
- rest_framework --- viewsets
viewsets :from rest_framework import viewsets #导入方式 ViewSetMixin(object): 这个类,大致作用就是重写了as_view()方法,假 ...