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. Python map/reduce/filter/sorted函数以及匿名函数

    1. map() 函数的功能: map(f, [x1,x2,x3]) = [f(x1), f(x2), f(x3)] def f(x): return x*x a = map(f, [1, 2, 3, ...

  2. 命令式编程 vs 声明式编程

    实际上我们绝大多数程序员都是在用命令式风格在编程, 这是和我们的冯诺依曼计算机机构密切相关的. (码农翻身注: 参见文章<冯诺依曼计算机的诞生>) 在一个冯诺依曼计算机中, 最核心的就是C ...

  3. pthread使用

    https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Multithreading/CreatingTh ...

  4. Netbackup用于技术支持的问题报告(报障模版)

    在与支持部门联系以报告问题之前,请填写以下信息. 日期: _________________________记录以下产品.平台和设备信息:■ 产品及其版本级别.■ 服务器硬件类型和操作系统级别.■ 客 ...

  5. linux服务基础之CentOS6编译安装mariadb

    1. 下载mariadb https://downloads.mariadb.org/mariadb/+releases/ 2. 解压到指定目录 # tar xf mariadb--linux-x86 ...

  6. 【洛谷P3834】(模板)可持久化线段树 1(主席树)

    [模板]可持久化线段树 1(主席树) https://www.luogu.org/problemnew/show/P3834 主席树支持历史查询,空间复杂度为O(nlogn),需要动态开点 本题用一个 ...

  7. 【luogu P3376 网络最大流】 模板

    题目链接:https://www.luogu.org/problemnew/show/P3376 #include <iostream> #include <cstdio> # ...

  8. linux学习(一)开始

    第一关 用u盘安装ubuntu, 大部份工作制作的安装U盘会失败,使用Win32DiskImager就行了,这个工具需要手动填写完整iso路径. 第二个问题 装完后发现乱码,连英文都乱码,不知道原因, ...

  9. Services 在多个 controller 中共享数据。

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...

  10. LeetCode16.最接近的三数之和 JavaScript

    给定一个包括 n 个整数的数组 nums 和 一个目标值 target.找出 nums 中的三个整数,使得它们的和与 target 最接近.返回这三个数的和.假定每组输入只存在唯一答案. 例如,给定数 ...