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 ...
随机推荐
- chpasswd
功能说明:从标准输入中读取一定格式的用户名.密码来批量更新用户的密码,其格式为 “用户名:密码”. 参数选项:-e 默认格式是明文密码,使用-e参数则需要加密的密码.
- windows网络模型之重叠IO(完成例程)的使用
#include <WINSOCK2.H> #include <stdio.h> #define PORT 5150 #define MSGSIZE 1024 #pragma ...
- POJ 1011 Sticks 【DFS 剪枝】
题目链接:http://poj.org/problem?id=1011 Sticks Time Limit: 1000MS Memory Limit: 10000K Total Submissio ...
- vue常用事件
一.事件监听 1. banner_edit.$watch('bannerForm.type', function () { //执行其他代码 console.log(666); this.banner ...
- 【luogu P3371 单源最短路径 】 模板 SPFA优化
无优化:500ms deque优化:400ms #include <queue> #include <cstdio> #include <cstring> #inc ...
- 解密Spring加载的Properties文件
Spring的框架中,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer类可以将.properties(key ...
- LeetCode10.正则表达式匹配 JavaScript
给定一个字符串 (s) 和一个字符模式 (p).实现支持 '.' 和 '*' 的正则表达式匹配. '.' 匹配任意单个字符. '*' 匹配零个或多个前面的元素. 匹配应该覆盖整个字符串 (s) ,而不 ...
- PL/SQL12的安装与使用
楼主比较懒,直接放一个别人的链接吧,比较全面. 大致过程就是,下载pl/sql 下载oracle instance client 然后配置oci.dll 添加 一个连接具体数据库的 ...
- 浅谈Java 8的新特性和使用场景
一.default方法: 通过default方法,可以在接口(Interface interface_name)中添加实例化方法: 代码如下: public interface TestDef ...
- NEC 框架规范 animation
/* animation *//* 淡入 */.a-fadein{-webkit-animation-name:fadein;-moz-animation-name:fadein;-ms-animat ...